home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / pondersr / ponder.cpp < prev    next >
C/C++ Source or Header  |  1996-05-06  |  75KB  |  2,524 lines

  1. /*                   ╒══════════════════════════════════╕
  2.                      │        PONDER -- the demo        │
  3.                      │           by winghead            │
  4.                      │ Copyright 1996 Joshua C. Shepard │
  5. ╒════════════════════╡       All Rights Reserved        ╞════════════════════╕
  6. ╞════════════════════╧══════════════════════════════════╧════════════════════╡
  7. │ Legal B.S.:                                                                │
  8. ╞════════════════════════════════════════════════════════════════════════════╡
  9. │ This source code is released to you with the permission of the author      │
  10. │ in order that you might learn from it. You MAY NOT use the source code     │
  11. │ directly in your own productions, or "rip" the code in any other manner.   │
  12. │ You are freely encouraged to use the ideas and methods however.            │
  13. │ The text/poem is also copyrighted by the author. It may not be used in any │
  14. │ form other than short quotes :)                                            │
  15. ╘════════════════════════════════════════════════════════════════════════════╛
  16. */
  17. /////////////////////////////////////////////////////////////////////////////
  18. // function header files
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <conio.h>
  23. #include <math.h>
  24. #include <string.h>
  25.  
  26. #include <mikmod.h>
  27. #include "real.h"
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // data header files:
  31. /////////////////////////////////////////////////////////////////////////////
  32. #include "skypal.h"
  33. #include "skypal2.h"
  34. #include "firepal.h"
  35. #include "raypal.h"
  36. #include "pondrpal.h"
  37. #include "water.h"
  38. #include "fontwid.h"
  39. #include "skullpal.h"
  40. #include "eyepal.h"
  41. #include "matchpal.h"
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // macros and constants:
  45. /////////////////////////////////////////////////////////////////////////////
  46. #define BUF_WIDTH 256
  47. #define BUF_HEIGHT 192
  48. #define AVG_CHAR_WIDTH 20
  49. #define BMP_WIDTH 256
  50. #define BMP_HEIGHT 256
  51. #define BMP_CNTR_X (BMP_WIDTH/2)
  52. #define BMP_CNTR_Y (BMP_HEIGHT/2)
  53.  
  54. #define BUF_CNTR_X (BUF_WIDTH/2)
  55. #define BUF_CNTR_Y (BUG_HEIGHT/2)
  56.  
  57. #define FieldBits 8
  58. #define FieldSize ( 1 << FieldBits )
  59. #define FieldBytes (FieldSize * FieldSize)
  60.  
  61. #define RADIX (32 - FieldBits)
  62. #define wrap(n)     (n & (FieldSize-1))
  63. #define MapIndex(x,y)  ((wrap(y) << FieldBits) + wrap(x))
  64.  
  65. #define Angle360 0x1000
  66. #define AngleMask (Angle360 - 1)
  67. #define Angle180 (Angle360 / 2)
  68. #define Angle90  (Angle360 / 4)
  69. #define Angle60  (Angle360 / 6)
  70. #define Angle45  (Angle360 / 8)
  71. #define Angle30  (Angle360 / 12)
  72. #define ViewAngle (Angle60 / 2)
  73.  
  74. #define SIN( x ) sinTable[(x) & AngleMask]
  75. #define COS( x ) sinTable[((x) + Angle90) & AngleMask]
  76.  
  77. #define DefaultPitch (BUF_HEIGHT / 2)
  78. #define YawAccel     (Angle360 / 256)
  79. #define VScale 0xa00;
  80. #define speed 0x200
  81.  
  82. /////////////////////////////////////////////////////////////////////////////
  83. // external variables (from compiled header files):
  84. /////////////////////////////////////////////////////////////////////////////
  85. extern unsigned char tube_pic[];
  86. extern unsigned char font[];
  87. extern unsigned char font_widths[];
  88. extern unsigned char ponderpic[];
  89. extern unsigned char skullpic[];
  90. extern unsigned char eyepic[];
  91. extern unsigned char matchpic[];
  92.  
  93. // mikmod variables:
  94. extern LOADER uniload;
  95. extern DRIVER gusdriver,sbdriver,nosnddriver;
  96. UWORD playertimer;
  97.  
  98. /////////////////////////////////////////////////////////////////////////////
  99. // global variables:
  100. /////////////////////////////////////////////////////////////////////////////
  101. int SCREEN_WIDTH;
  102. int SCREEN_HEIGHT;
  103. unsigned char* buf1;
  104. // sky renderer globals
  105. long sinTable[Angle360];
  106. unsigned char HeightMap[FieldBytes];
  107. unsigned char SkyMap[FieldBytes];
  108. int xOrg = 128L << 16;
  109. int yOrg = 128L << 16;
  110. long Altitude = 220;
  111. int Yaw = Angle90;
  112. int Pitch = DefaultPitch;
  113. // a pointer to the drawing function
  114. void (*ShowPic)( unsigned char* pic );
  115.  
  116.  
  117. /////////////////////////////////////////////////////////////////////////////
  118. // interrupt handlers:
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CLOCK TICK HANDLER FOR MIKMOD
  121. void tickhandler( void )
  122. {
  123.     MP_HandleTick();    // play 1 tick of the module
  124.     MD_SetBPM(mp_bpm);
  125. }
  126.  
  127.  
  128. /////////////////////////////////////////////////////////////////////////////
  129. // inline asm functions:
  130. /////////////////////////////////////////////////////////////////////////////
  131.  
  132. void SetVidMode( short );
  133. #pragma aux SetVidMode = \
  134.     "int 10h"            \
  135.     parm [ax];
  136.  
  137. // PUTS A 256x192 PIC TO THE SCREEN IN LIKET MODE
  138. void ShowPicLiket( unsigned char* pic );
  139. #pragma aux ShowPicLiket = \
  140.     "mov edi, 0xa0000" \
  141.     "mov ecx, 12288" \
  142.     "rep movsd" \
  143.     parm [esi] modify [edi ecx];
  144.  
  145. void ShowPic256( unsigned char* pic )
  146. {
  147.     ShowPicLiket( pic );
  148. }
  149.  
  150. // PUTS A 256x200 PIC TO A MODE 13H SCREEN
  151. void ShowPic13h( unsigned char* pic );
  152. #pragma aux ShowPic13h =     \
  153.     "mov edi, 0xa0520"    \
  154.     "mov ebx, 192"        \
  155.   "looper:"               \
  156.     "mov ecx, 64"         \
  157.     "rep movsd"           \
  158.     "add edi, 64"         \
  159.     "dec ebx"             \
  160.     "jnz looper"          \
  161.     parm [esi] modify [ecx edi ebx];
  162.  
  163. void ShowPic320( unsigned char* pic )
  164. {
  165.     ShowPic13h( pic );
  166. }
  167.  
  168. // WAITS FOR THE VERTICAL RETRACE
  169. void WaitRetrace();
  170. #pragma aux WaitRetrace = \
  171.      "  mov  dx,03dah"    \
  172.      "looper:     "       \
  173.      "  in   al,dx"       \
  174.      "  and  al,8"        \
  175.      "  jz   looper"      \
  176.      modify [dx al];
  177.  
  178. // WAITS FOR NO VERTICAL RETRACE
  179. void WaitNoRetrace();
  180. #pragma aux WaitNoRetrace = \
  181.     "  mov dx, 03dah" \
  182.     "looper: " \
  183.     "  in al, dx" \
  184.     "  and al, 8" \
  185.     "  jnz looper" \
  186.     modify [dx al];
  187.  
  188. // CLEARS A BUFFER (SIZE MUST BE EVENLY DIVSIBLE BY 4)
  189. void ClearBuf( unsigned char* buf, int size );
  190. #pragma aux ClearBuf = \
  191.     "mov eax, 0" \
  192.     "shr ecx, 2" \
  193.     "rep stosd" \
  194.     parm [edi][ecx] modify [eax];
  195.  
  196. void SetPalReg( int color, int red, int green, int blue);
  197. #pragma aux SetPalReg =     \
  198.     "mov dx, 03c8h"         \
  199.     "out dx, al"            \
  200.     "inc dx"                \
  201.     "mov ax, bx"            \
  202.     "out dx, al"            \
  203.     "mov ax, cx"            \
  204.     "out dx, al"            \
  205.     "mov ax, di"            \
  206.     "out dx, al"            \
  207.     parm [eax][ebx][ecx][edi]   \
  208.     modify [edx];
  209.  
  210. // COPIES A PALETTE TO ANOTHER PALETTE
  211. void CopyPal( unsigned char* dest, unsigned char* src );
  212. #pragma aux CopyPal = \
  213.     "mov ecx, 192" \
  214.     "rep movsd" \
  215.     parm [edi][esi] modify [ecx];
  216.  
  217. int CalcOffset( int u, int v );
  218. #pragma aux CalcOffset = \
  219.     "mov ebx, edx"       \
  220.     "shr ebx, 32 - 8"    \
  221.     "shld ebx, ecx, 8"   \
  222.     parm [ecx][edx] value [ebx];
  223.  
  224.  
  225. /////////////////////////////////////////////////////////////////////////////
  226. // functions:
  227. /////////////////////////////////////////////////////////////////////////////
  228.  
  229. // GETS THE VALUES OF ONE PALETTE REGISTER
  230. void GetPalReg( short index, unsigned char* r, unsigned char* g,
  231.     unsigned char* b)
  232. {
  233.     outpw( 0x3c6, 0xff );        //Enable reading
  234.     outpw( 0x3c7, index );       //from register# 'index'
  235.     *r = (unsigned char)inp( 0x3c9 );    //now get the values:
  236.     *g = (unsigned char)inp( 0x3c9 );
  237.     *b = (unsigned char)inp( 0x3c9 );
  238. }
  239.  
  240. void SetPal( unsigned char* pal )
  241. {
  242.     int count = 0;
  243.     short int r, g, b;
  244.     do
  245.     {
  246.         r = pal[count * 3];
  247.         g = pal[count * 3 + 1];
  248.         b = pal[count * 3 + 2];
  249.         SetPalReg( count, r, g, b );
  250.         count++;
  251.     }
  252.     while( count < 256 );
  253. }
  254.  
  255. // fades out a section of 16 colors one step
  256. void FadeOutRing( unsigned char* pal, int color1, int step )
  257. {
  258.     int count;
  259.     for( count = color1; count < color1 + 16*3; count++ )
  260.     {
  261.         if( pal[count] > step ) pal[count] -= step;
  262.         if( pal[count+1] > step ) pal[count+1] -= step;
  263.         if( pal[count+2] > step ) pal[count+2] -= step;
  264.     }
  265.     SetPal( pal );
  266. }
  267.  
  268. // blacks out a section of 16 colors
  269. void BlackOutRing( unsigned char* pal, int color1 )
  270. {
  271.     int count;
  272.     for( count = color1; count < color1 + 16*3; count++ )
  273.     {
  274.         pal[count] = 0;
  275.         pal[count+1] = 0;
  276.         pal[count+2] = 0;
  277.     }
  278.     SetPal( pal );
  279. }
  280.  
  281. // sets a section of 16 colors to a rgb value
  282. void SetRingColor( unsigned char* pal, int color1, int r, int g, int b )
  283. {
  284.     int count;
  285.     for( count = color1; count < color1 + 16*3; count++ )
  286.     {
  287.         pal[count] = r;
  288.         pal[count+1] = g;
  289.         pal[count+2] = b;
  290.     }
  291.     SetPal( pal );
  292. }
  293.  
  294. // builds x,y tables for the screen->bitmap translation
  295. // pointers must be pre-allocated BUF_HEIGHT*BUF_WIDTH bytes
  296. void MakeTexMapTables( unsigned char* xmap, unsigned char* ymap )
  297. {
  298.     double x, y, r, xy2, z, t ,l, sd;
  299.     long zc;
  300.     unsigned char col, col2;
  301.     int xp, yp, adr;
  302.     int off;
  303.     unsigned char    i;
  304.  
  305.     //radius
  306.     r = 50;
  307.     //dist between viewer & screen
  308.     sd = 400;
  309.     adr = 0;
  310.  
  311.     for ( y=-BUF_HEIGHT/2; y<=(BUF_HEIGHT/2-1); y++ )
  312.     {
  313.         yp = y;
  314.         for ( x=-(BUF_WIDTH/2); x<=(BUF_WIDTH/2 -1); x++ )
  315.         {
  316.             xy2 = fabs(( x * x ) + ( y * y ));
  317.             xy2 = sqrt( xy2 );
  318.             if (xy2 != 0)
  319.               l = r / xy2;
  320.             z = l * sd;
  321.             if (z < 20000)
  322.             {
  323.                 if ((x != 0) && (y != 0))
  324.                 {
  325.                     t = atan( y / x );
  326.                     t = 256 * t / ( 2 * PI );
  327.                     if ((x <= 0) && (y <= 0))
  328.                       t++;
  329.                     if ((x > 0) && (y > 0))
  330.                       t++;
  331.                     if (x >= 0)
  332.                       t = t+128;
  333.                 }
  334.  
  335.                 zc = ceil( z / 4 );
  336.                 zc = (int)zc % 256;
  337.                 col = zc;
  338.                 xmap[((int)y+BUF_HEIGHT/2)*BUF_WIDTH + ((int)x+BUF_WIDTH/2)] = col;
  339.  
  340.                 col = t;
  341.                 if ((y == 0) && (x < 0))
  342.                   col = 1;
  343.                 ymap[((int)y+BUF_HEIGHT/2)*BUF_WIDTH + ((int)x+BUF_WIDTH/2)] = col;
  344.             }
  345.             else
  346.             {
  347.                 col = 0;
  348.                 xmap[((int)y+BUF_HEIGHT/2)*BUF_WIDTH + ((int)x+BUF_WIDTH/2)] = col;
  349.                 ymap[((int)y+BUF_HEIGHT/2)*BUF_WIDTH + ((int)x+BUF_WIDTH/2)] = col;
  350.             }
  351.             adr++;
  352.         }
  353.     }
  354. }
  355.  
  356. // builds x,y tables for the screen->bitmap translation, NOT A TUBE
  357. // pointers must be pre-allocated BUF_HEIGHT*BUF_WIDTH bytes
  358. void MakeTexMapTables2( unsigned char* xmap, unsigned char* ymap )
  359. {
  360.     double x, y, r, xy2, z, t ,l, sd;
  361.     long zc;
  362.     unsigned char col, col2;
  363.     int xp, yp, adr;
  364.     int off;
  365.     unsigned char    i;
  366.  
  367.     //radius
  368.     r = 50;
  369.     adr = 0;
  370.  
  371.     for ( y=-BUF_HEIGHT/2; y<=(BUF_HEIGHT/2-1); y++ )
  372.     {
  373.         yp = y;
  374.         for ( x=-(BUF_WIDTH/2); x<=(BUF_WIDTH/2 -1); x++ )
  375.         {
  376.             xy2 = fabs(( x * x ) + ( y * y ));
  377.             xy2 = sqrt( xy2 );
  378.             if (xy2 != 0)
  379.               l = r / xy2;
  380.             if ((x != 0) && (y != 0))
  381.             {
  382.                 t = atan( y / x );
  383.                 t = 256 * t / ( 2 * PI );
  384.                 if ((x <= 0) && (y <= 0))
  385.                   t++;
  386.                 if ((x > 0) && (y > 0))
  387.                   t++;
  388.                 if (x >= 0)
  389.                   t = t+128;
  390.             }
  391.  
  392.             col = (unsigned char)l % 256;
  393.             xmap[((int)y+BUF_HEIGHT/2)*BUF_WIDTH + ((int)x+BUF_WIDTH/2)] = col;
  394.  
  395.             col = t;
  396.             if ((y == 0) && (x < 0))
  397.               col = 1;
  398.             ymap[((int)y+BUF_HEIGHT/2)*BUF_WIDTH + ((int)x+BUF_WIDTH/2)] = col;
  399.             adr++;
  400.         }
  401.     }
  402. }
  403.  
  404. // builds a table of radii for the screen
  405. // pointer must be pre-allocated BUF_HEIGHT*BUF_WIDTH bytes
  406. void MakeRadTable( unsigned char* table, unsigned char* table2, unsigned char* table3 )
  407. {
  408.     double r;
  409.     double x2, y2;
  410.     int rad, rad2;
  411.  
  412.     // for each point:
  413.     for( int row = 0; row < BUF_HEIGHT; row++ )
  414.     {
  415.         for( int col = 0; col < BUF_WIDTH; col++ )
  416.         {
  417.             // find the distance from the center of the screen at this point:
  418.             x2 = (col-BUF_WIDTH/2) * (col-BUF_WIDTH/2);
  419.             y2 = (row-BUF_HEIGHT/2) * (row-BUF_HEIGHT/2);
  420.             r = sqrt( x2 + y2 );
  421.             rad = (int)ceil( r );
  422.             rad2 = (int)(r * 0.625 );
  423.  
  424.             table3[row * BUF_WIDTH + col] = (unsigned char)rad2;
  425.             table2[row * BUF_WIDTH + col] = (unsigned char)rad / 10;
  426.             table[row * BUF_WIDTH + col] = (unsigned char)rad / 21;
  427.  
  428.         }
  429.     }
  430. }
  431.  
  432. // SET A 256x192 SQUARE ASPECT 50Hz VIDEO MODE. MODE 13H *MUST* BE SET FIRST!
  433. void SetLiketMode( void )
  434. {
  435.     int t;
  436.     outp( 0x3d4, 0x11 );
  437.     t = inp( 0x3d5 );
  438.     outp( 0x3d5, t & 0x7f );
  439.     outp( 0x3c2, 0x63 );
  440.     outp( 0x3d4, 0x00 );
  441.     outp( 0x3d5, 0x50 );
  442.     outp( 0x3D4, 0x1 );
  443.     outp( 0x3D5, 0x3F );
  444.     outp( 0x3D4, 0x2 );
  445.     outp( 0x3D5, 0x40 );
  446.     outp( 0x3D4, 0x3 );
  447.     outp( 0x3D5, 0x8B );
  448.     outp( 0x3D4, 0x4 );
  449.     outp( 0x3D5, 0x41 );
  450.     outp( 0x3D4, 0x5 );
  451.     outp( 0x3D5, 0x3 );
  452.     outp( 0x3D4, 0x6 );
  453.     outp( 0x3D5, 0xF3 );
  454.     outp( 0x3D4, 0x7 );
  455.     outp( 0x3D5, 0xF0 );
  456.     outp( 0x3D4, 0x8 );
  457.     outp( 0x3D5, 0x0 );
  458.     outp( 0x3D4, 0x9 );
  459.     outp( 0x3D5, 0x62 );
  460.     outp( 0x3D4, 0x10 );
  461.     outp( 0x3D5, 0x93 );
  462.     outp( 0x3D4, 0x11 );
  463.     outp( 0x3D5, 0x8C );
  464.     outp( 0x3D4, 0x12 );
  465.     outp( 0x3D5, 0x41 );
  466.     outp( 0x3D4, 0x13 );
  467.     outp( 0x3D5, 0x20 );
  468.     outp( 0x3D4, 0x14 );
  469.     outp( 0x3D5, 0x40 );
  470.     outp( 0x3D4, 0x15 );
  471.     outp( 0x3D5, 0x58 );
  472.     outp( 0x3D4, 0x16 );
  473.     outp( 0x3D5, 0x70 );
  474.     outp( 0x3D4, 0x17 );
  475.     outp( 0x3D5, 0xA3 );
  476.     outp( 0x3C4, 0x1 );
  477.     outp( 0x3C5, 0x1 );
  478.     outp( 0x3C4, 0x3 );
  479.     outp( 0x3C5, 0x0 );
  480.     outp( 0x3C4, 0x4 );
  481.     outp( 0x3C5, 0xE );
  482.     outp( 0x3CE, 0x5 );
  483.     outp( 0x3CF, 0x40 );
  484.     outp( 0x3CE, 0x6 );
  485.     outp( 0x3CF, 0x5 );
  486. }
  487.  
  488. // WARNING: HANDLES ONLY a - z (LOWER CASE ONLY) and '?' !!!
  489. // WILL *BARF* ON OTHER INPUT :)
  490. void DrawChar( char index, int x, int y, unsigned char* buf )
  491. {
  492.     unsigned char* letter;
  493.     unsigned char color;
  494.  
  495.     letter = font + index * 28 * 40;
  496.     buf = buf + y * BUF_WIDTH + x;
  497.  
  498.     for( int row = 0; row < 40; row++ )
  499.     {
  500.         for( int col = 0; col < 28; col++ )
  501.         {
  502.             color = letter[row * 28 + col];
  503.             if( color != 0 ) *buf++ = color;
  504.             else buf++;
  505.         }
  506.         buf += BUF_WIDTH-28;
  507.     }
  508. }
  509.  
  510. // DRAW THE STRING IN THE VARIABLE WIDTH FONT( WOO HOO! )
  511. void DrawText( char* s, int x, int y, unsigned char* buf )
  512. {
  513.     char index;
  514.  
  515.     BEGIN:
  516.     while( (index = *s) != 0 )
  517.     {
  518.         if( index == ' ' )
  519.         {
  520.             s++;
  521.             x += 20;
  522.             goto BEGIN;
  523.         }
  524.         else if( index == '?' ) index = 26;
  525.         else index = index - 97;
  526.  
  527.         DrawChar( index, x, y, buf );
  528.         s++;
  529.         x += font_widths[index];
  530.     }
  531. }
  532.  
  533. //GET THE CURRENT PALETTE
  534. void GetPalette( unsigned char* pal )
  535. {
  536.     int count;
  537.     // get the current palette:
  538.     for( count = 0; count < 256; count++ )
  539.     {
  540.         GetPalReg( count, &pal[count*3], &pal[count*3+1], &pal[count*3+2] );
  541.     }
  542. }
  543.  
  544. // SETS THE A PALETTE RANGE (C2 - C2) TO A GRADIENT
  545. void SetFadePalette(int r1, int g1, int b1, int r2, int g2, int b2, int c1,
  546.                     int c2)
  547. {
  548.     int dr, dg, db, r, g, b, count;
  549.  
  550.     r = r1 << 8;
  551.     g = g1 << 8;
  552.     b = b1 << 8;
  553.  
  554.     dr = ((r2 - r1) << 8) / (c2 - c1);
  555.     dg = ((g2 - g1) << 8) / (c2 - c1);
  556.     db = ((b2 - b1) << 8) / (c2 - c1);
  557.  
  558.     outp(0x3c8, c1);
  559.  
  560.     for (count = c1; count <= c2; count++)
  561.     {
  562.         outp(0x3c9, r >> 8);
  563.         outp(0x3c9, g >> 8);
  564.         outp(0x3c9, b >> 8);
  565.  
  566.         r += dr;
  567.         g += dg;
  568.         b += db;
  569.     }
  570. }
  571.  
  572. // FADES THE PALETTE OUT TO BLACK. RETURNS TRUE IF DONE
  573. int FadeOut( unsigned char* pal )
  574. {
  575.     static int i = 0;
  576.     int count;
  577.     if( i < 64 )
  578.     {
  579.         for( count = 0; count < 768; count++ )
  580.         {
  581.             if( pal[count] > 0 ) pal[count]--;
  582.         }
  583.         WaitRetrace();
  584.         SetPal( pal );
  585.         i++;
  586.         return 0;
  587.     }
  588.     else
  589.     {
  590.         i = 0;
  591.         return 1;
  592.     }
  593. }
  594.  
  595. // FADES IN PROPORTIONATELY. RETURNS TRUE WHEN DONE
  596. int FadeIn( unsigned char* pal )
  597. {
  598.     static unsigned char cur_pal[768];
  599.     int count;
  600.     static int i = 0;
  601.     int j;
  602.  
  603.     //move all values smoothly to their pal value:
  604.     for( j = 0; j < 256; j++ )
  605.     {
  606.         cur_pal[j*3] = ( pal[j*3] * i / 64 );
  607.         cur_pal[j*3+1] = ( pal[j*3+1] * i / 64 );
  608.         cur_pal[j*3+2] = ( pal[j*3+2] * i / 64 );
  609.     }
  610.     //wait for the vertical retrace, to avoid "snow":
  611.     while( inp( 0x3da ) & 0x08 ){}
  612.     while( !(inp( 0x3da ) & 0x08 )){}
  613.  
  614.     for( count = 0; count < 256; count++ )
  615.     {
  616.         SetPalReg( count, cur_pal[count*3], cur_pal[count*3+1],
  617.                   cur_pal[count*3+2] );
  618.     }
  619.     i++;
  620.     if( i == 63 )
  621.     {
  622.         i = 0;
  623.         //set all values to pal values:
  624.         for( count = 0; count < 256; count++ )
  625.         {
  626.             SetPalReg( count, pal[count*3], pal[count*3+1], pal[count*3+2] );
  627.         }
  628.         return 1;
  629.     }
  630.     else return 0;
  631. }
  632.  
  633. // FADES THE PALETTE OUT TO WHITE. RETURNS TRUE IF DONE
  634. int FadeToWhite( unsigned char* pal )
  635. {
  636.     static int i = 0;
  637.     int count;
  638.     if( i < 64 )
  639.     {
  640.         for( count = 0; count < 768; count++ )
  641.         {
  642.             if( pal[count] < 63 ) pal[count]++;
  643.         }
  644.         WaitRetrace();
  645.         SetPal( pal );
  646.         i++;
  647.         return 0;
  648.     }
  649.     else
  650.     {
  651.         i = 0;
  652.         return 1;
  653.     }
  654. }
  655.  
  656. // RETURNS TRUE IF VOLUME IS ALL THE WAY FADED IN
  657. int FadeMusicIn( void )
  658. {
  659.     if( mp_volume == 100 ) return 1;
  660.     else
  661.     {
  662.         mp_volume++;
  663.         return 0;
  664.     }
  665. }
  666.  
  667. // RETURNS TRUE IF VOLUME IS ALL THE WAY FADED OUT
  668. int FadeMusicOut( void )
  669. {
  670.     if( mp_volume == 0 ) return 1;
  671.     else
  672.     {
  673.         mp_volume--;
  674.         return 0;
  675.     }
  676. }
  677.  
  678. // ROTATES AND TILES A BITMAP EVERY OTHER LINE IN DIFFERENT DIRECTIONS AND DIFF COLOR:
  679. void RotateBmp( unsigned char* buf, unsigned char* bmp, mangle angle, real scale )
  680. {
  681.     unsigned char* dest;
  682.     real u, v, row_u, row_v, start_u, start_v;
  683.     real du_col, dv_col, du_row, dv_row;
  684.     int x, y;
  685.  
  686.     // center of the 256 x 256 bitmap:
  687.     start_u = INT_TO_REAL( BMP_CNTR_X );
  688.     start_v = INT_TO_REAL( BMP_CNTR_Y );
  689.  
  690.     // calculate the deltas:
  691.     du_col = xGetCos( angle );
  692.     dv_col = xGetSin( angle );
  693.  
  694.     du_col = Mul( du_col, scale );
  695.     dv_col = Mul( dv_col, scale );
  696.  
  697.     du_row = -dv_col;
  698.     dv_row = du_col;
  699.  
  700.     start_u -= BMP_CNTR_X * du_col + BMP_CNTR_Y * du_col;
  701.     start_v -= BMP_CNTR_X * dv_col + BMP_CNTR_Y * dv_col;
  702.  
  703.     row_u = start_u;
  704.     row_v = start_v;
  705.  
  706.     dest = buf;
  707.     for( y = 0; y < BUF_HEIGHT; y +=2 )
  708.     {
  709.         u = row_u;
  710.         v = row_v;
  711.         for( x = 0; x < BUF_WIDTH; x++ )
  712.         {
  713.             *dest++ = bmp[(REAL_TO_INT( u ) & 255 ) + (REAL_TO_INT( v ) & 255 ) * 256];
  714.             u += du_col;
  715.             v += dv_col;
  716.         }
  717.         dest += BUF_WIDTH;
  718.         row_u += du_row;
  719.         row_v += dv_row;
  720.     }
  721.     dest = buf + BUF_WIDTH;
  722.     for( y = 1; y < BUF_HEIGHT; y += 2 )
  723.     {
  724.         u = row_u;
  725.         v = row_v;
  726.         for( x = 0; x < BUF_WIDTH; x++ )
  727.         {
  728.             *dest++ = bmp[(REAL_TO_INT( u ) & 255 ) + (REAL_TO_INT( v ) & 255 ) * 256]+128;
  729.             u -= du_row;
  730.             v -= dv_row;
  731.         }
  732.         dest += BUF_WIDTH;
  733.         row_u -= du_col;
  734.         row_v -= dv_col;
  735.     }
  736. }
  737.  
  738. // INITIALIZE SIN TABLE IN 16.16 FIXED POINT:
  739. void InitSkySinTable( void )
  740. {
  741.     int i;
  742.     for( i = 0; i < Angle180; i++ )
  743.     {
  744.         sinTable[i] = sin((double)i * PI / Angle180) * 0x10000L;
  745.     }
  746.  
  747.     for( i = Angle180; i < Angle360; i++ )
  748.     {
  749.         sinTable[i] = -sinTable[i - Angle180];
  750.     }
  751. }
  752.  
  753. char RandomColor(int c, int n, int d)
  754. {
  755.     int p;
  756.     int rand_color = (int)rand() / (RAND_MAX / (n<<1));
  757.     p = (c + n - rand_color) / d - 1;
  758.     if (p > 255)
  759.     {
  760.         p = 255;
  761.     }
  762.     if (p < 0)
  763.     {
  764.         p = 0;
  765.     }
  766.     return p;
  767. }
  768.  
  769. // RECURSIVE FUNCTION TO CREATE A FRACTAL TERRAIN MAP
  770. void CreateFractalMap( int startx, int starty, int endx, int endy )
  771. {
  772.     int pt1, pt2, pt3, pt4;
  773.     int x2, y2;
  774.     int d;
  775.  
  776.     // check for need for further recursion:
  777.     if (((endx-startx) < 2) && ((endy-starty) < 2)) return;
  778.  
  779.     pt1 = HeightMap[MapIndex( startx, starty )];
  780.     pt2 = HeightMap[MapIndex( startx, endy )];
  781.     pt3 = HeightMap[MapIndex( endx, starty )];
  782.     pt4 = HeightMap[MapIndex( endx, endy )];
  783.  
  784.     x2 = (endx+startx) >> 1;
  785.     y2 = (endy+starty) >> 1;
  786.     d = 5 * (endx - startx + endy - starty) / 3;
  787.  
  788.     if (HeightMap[MapIndex( startx, y2 )] == 0)
  789.       HeightMap[MapIndex( startx, y2 )] = RandomColor( pt2+pt4, d, 2 );
  790.     if (HeightMap[MapIndex( endx, y2 )] == 0)
  791.       HeightMap[MapIndex( endx, y2 )] = RandomColor( pt3+pt4, d, 2 );
  792.     if (HeightMap[MapIndex( x2, starty )] == 0)
  793.       HeightMap[MapIndex( x2, starty )] = RandomColor( pt1+pt3, d, 2 );
  794.     if (HeightMap[MapIndex( x2, endy )] == 0)
  795.       HeightMap[MapIndex( x2, endy )] = RandomColor( pt1+pt2, d, 2 );
  796.  
  797.     HeightMap[MapIndex( x2, y2 )] = RandomColor( pt1+pt2+pt3+pt4, d, 4 );
  798.  
  799.     // recurse for each new 'quadrant':
  800.     CreateFractalMap( startx, starty, x2, y2 );
  801.     CreateFractalMap( x2, starty, endx, y2 );
  802.     CreateFractalMap( startx, y2, x2, endy );
  803.     CreateFractalMap( x2, y2, endx, endy );
  804. }
  805.  
  806. void AverageMapVals()
  807. {
  808.     int x, y;
  809.  
  810.     for (x = 0; x < FieldSize; x++)
  811.     {
  812.         for (y = 0; y < FieldSize; y++)
  813.         {
  814.             HeightMap[MapIndex( x, y )] =
  815.               ( HeightMap[MapIndex( x,  y - 1 )] +
  816.                HeightMap[MapIndex( x,  y + 1 )] +
  817.                HeightMap[MapIndex( x - 1,y - 1 )] +
  818.                HeightMap[MapIndex( x - 1,y + 1 )] +
  819.                HeightMap[MapIndex( x + 1,y - 1 )] +
  820.                HeightMap[MapIndex( x + 1,y + 1 )] +
  821.                HeightMap[MapIndex( x - 1,y )] +
  822.                HeightMap[MapIndex( x + 1,y )] ) >> 3;
  823.         }
  824.     }
  825. }
  826.  
  827. // LOAD THE HEIGHT FIELD DATA:
  828. void InitSkyMapper( void )
  829. {
  830.     int count, row, col;
  831.     printf( "Creating Fractal...\n" );
  832.     CreateFractalMap( 0, 0, FieldSize, FieldSize );
  833.     for( count = 0; count < 5; count++ ) AverageMapVals();
  834.     for( row = 0; row < FieldSize; row++ )
  835.     {
  836.         for( col = 0; col < FieldSize; col++ )
  837.         {
  838.             SkyMap[row * FieldSize + col] =
  839.               (HeightMap[row * FieldSize + col]>>1);
  840.         }
  841.     }
  842.     InitSkySinTable();
  843. }
  844.  
  845. // SETUP A PALETTE GRADIENT FROM ONE VALUE TO ANOTHER:
  846. void SetPaletteSpread( int r1, int g1, int b1, int r2, int g2, int b2,
  847.                     int c1, int c2 )
  848. {
  849.     int dr, dg, db, r, g, b;
  850.  
  851.     r = r1 << 8;
  852.     g = g1 << 8;
  853.     b = b1 << 8;
  854.  
  855.     dr = ((r2 - r1) << 8) / (c2 - c1);
  856.     dg = ((g2 - g1) << 8) / (c2 - c1);
  857.     db = ((b2 - b1) << 8) / (c2 - c1);
  858.  
  859.     outp(0x3c8, c1);
  860.  
  861.     for( int count = c1; count <= c2; count++ )
  862.     {
  863.         outp( 0x3c9, r >> 8 );
  864.         outp( 0x3c9, g >> 8 );
  865.         outp( 0x3c9, b >> 8 );
  866.  
  867.         r += dr;
  868.         g += dg;
  869.         b += db;
  870.     }
  871. }
  872.  
  873. void CastSkyRay( int col, int horiz, int dx, int dy )
  874. {
  875.     int x, y, z;
  876.     int pixel, offset;
  877.     unsigned char c;
  878.  
  879.     // point to the top of the column:
  880.     pixel = col;
  881.  
  882.     // initial coordinates:
  883.     x = xOrg << (16 - FieldBits);
  884.     y = yOrg << (16 - FieldBits);
  885.  
  886.     while( pixel <= horiz * BUF_WIDTH )
  887.     {
  888.         y += dy;
  889.         x += dx;
  890.  
  891.         // calculate the offset in the height field
  892.         offset = CalcOffset( x, y );
  893.  
  894.         c = SkyMap[offset];
  895.         buf1[pixel] = c;  // draw pixel
  896.         pixel += BUF_WIDTH;
  897.     }
  898. }
  899.  
  900. // ONLY DOES EVERY OTHER PIXEL (EVEN PIXELS)
  901. void CastSkyRay2( int col, int horiz, int dx, int dy )
  902. {
  903.     int x, y, z;
  904.     int pixel, offset;
  905.     unsigned char c;
  906.  
  907.     // point to the top of the column:
  908.     pixel = col;
  909.  
  910.     // lets go 2 pixels at a time:
  911.     dx <<= 1;
  912.     dy <<= 1;
  913.  
  914.     // initial coordinates:
  915.     x = xOrg << (16 - FieldBits);
  916.     y = yOrg << (16 - FieldBits);
  917.  
  918.     while( pixel < horiz * BUF_WIDTH )
  919.     {
  920.         y += dy;
  921.         x += dx;
  922.  
  923.         // calculate the offset in the height field
  924.         offset = CalcOffset( x, y );
  925.  
  926.         c = SkyMap[offset];
  927.         buf1[pixel] = c;  // draw pixel
  928.         pixel += (BUF_WIDTH<<1);
  929.     }
  930. }
  931.  
  932. // ONLY DOES EVERY OTHER PIXEL (ODD PIXELS), UPSIDE DOWN
  933. void CastSkyRay3( int col, int horiz, int dx, int dy )
  934. {
  935.     int x, y, z;
  936.     int pixel, offset;
  937.     unsigned char c;
  938.  
  939.     // point to the top of the column:
  940.     pixel = BUF_WIDTH * (BUF_HEIGHT-1) + col;
  941.  
  942.     // lets go 2 pixels at a time:
  943.     dx <<= 1;
  944.     dy <<= 1;
  945.  
  946.     // initial coordinates:
  947.     x = xOrg << (16 - FieldBits);
  948.     y = yOrg << (16 - FieldBits);
  949.  
  950.     while( pixel >= col )
  951.     {
  952.         y += dy;
  953.         x += dx;
  954.  
  955.         // calculate the offset in the height field
  956.         offset = CalcOffset( x, y );
  957.  
  958.         c = SkyMap[offset];
  959.         buf1[pixel] = c;  // draw pixel
  960.         pixel -= (BUF_WIDTH<<1);
  961.     }
  962. }
  963.  
  964.  
  965. /////////////////////////////////////////////////////////////////////////////
  966. // main routine
  967. /////////////////////////////////////////////////////////////////////////////
  968.  
  969. void main( int argc, char* argv[] )
  970. {
  971.     unsigned char pal[768];
  972.     unsigned char* tube_x;
  973.     unsigned char* tube_y;
  974.     unsigned char* circ_x;
  975.     unsigned char* circ_y;
  976.     // radii from 0-15
  977.     unsigned char* radii;
  978.     // radii from 0 - 127, that loops from 127 back to 0 (not quite radii)
  979.     unsigned char* radii2;
  980.     unsigned char* radii3;
  981.  
  982.     unsigned char* screen = (unsigned char*)0xa0000;
  983.  
  984.     FILE* file;
  985.  
  986.     int row, col;
  987.     int offs;
  988.     unsigned char x, y;
  989.     int color;
  990.     unsigned char x_off, y_off;
  991.     unsigned char x_off2;
  992.     unsigned char y_off2;
  993.     int color_offs;
  994.     int done;
  995.     int count;
  996.  
  997.     //get command line argument:
  998.     // if there isn't any, default to tweaked mode
  999.     if( argc < 2 )
  1000.     {
  1001.         SCREEN_WIDTH = 256;
  1002.         SCREEN_HEIGHT = 192;
  1003.         ShowPic = ShowPic256;
  1004.     }
  1005.     // else if the paramter is "13h" use mode 13h
  1006.     else if ( strcmp( argv[1], "13h" ) == 0 )
  1007.     {
  1008.         SCREEN_WIDTH = 320;
  1009.         SCREEN_HEIGHT = 200;
  1010.         ShowPic = ShowPic320;
  1011.     }
  1012.     // otherwise exit with a help message
  1013.     else
  1014.     {
  1015.         printf( "In order to run this demo in mode 13h, type 'ponder 13h'\n" );
  1016.         printf( "The default is to use a 50Hz 256x192 tweaked mode.\n" );
  1017.         return;
  1018.     }
  1019.  
  1020.     // allocate memory for the data files:
  1021.     tube_x = new unsigned char[BUF_WIDTH * BUF_HEIGHT];
  1022.     tube_y = new unsigned char[BUF_WIDTH * BUF_HEIGHT];
  1023.     circ_x = new unsigned char[BUF_WIDTH * BUF_HEIGHT];
  1024.     circ_y = new unsigned char[BUF_WIDTH * BUF_HEIGHT];
  1025.  
  1026.     radii = new unsigned char[BUF_WIDTH * BUF_HEIGHT];
  1027.     radii2 = new unsigned char[BUF_WIDTH * BUF_HEIGHT];
  1028.     radii3 = new unsigned char[BUF_WIDTH * BUF_HEIGHT];
  1029.     buf1 = new unsigned char[BUF_WIDTH * BUF_HEIGHT];
  1030.  
  1031.     if( !tube_x || !tube_y || !tube_pic || !radii || !radii2 || !radii3 ||
  1032.         !circ_x || !circ_y || !buf1 )
  1033.     {
  1034.         delete tube_x;
  1035.         delete tube_y;
  1036.         delete circ_x;
  1037.         delete circ_y;
  1038.         delete radii;
  1039.         delete radii2;
  1040.         delete radii3;
  1041.         delete buf1;
  1042.         return;
  1043.     }
  1044.  
  1045.     // clear buf1
  1046.     ClearBuf( buf1, BUF_WIDTH * BUF_HEIGHT );
  1047.  
  1048.     // generate tables:
  1049.     printf( "Performing heavy calculations, please stand by...\n" );
  1050.     MakeTexMapTables( tube_x, tube_y );
  1051.     MakeTexMapTables2( circ_x, circ_y );
  1052.     MakeRadTable( radii, radii3, radii2 );
  1053.  
  1054.     // create the cloud fractal:
  1055.     InitSkyMapper();
  1056.  
  1057.     // initialize fixed point math tables:
  1058.     xInitCosSin();
  1059.  
  1060.     // start the music player:
  1061.     //MIKMOD stuff://////////////////////////////////////////////////////////
  1062.     UNIMOD *mf;
  1063.     md_mixfreq      =44100;                     // standard mixing freq
  1064.     md_dmabufsize   =10000;                     // standard dma buf size
  1065.     md_mode         =DMODE_16BITS|DMODE_STEREO; // standard mixing mode
  1066.     md_device       =0;                         // standard device: autodetect
  1067.     // Register the loaders we want to use..
  1068.     ML_RegisterLoader(&load_uni);
  1069.  
  1070.     // Register the drivers we want to use:
  1071.     MD_RegisterDriver(&drv_nos);
  1072.     MD_RegisterDriver(&drv_ss);
  1073.     MD_RegisterDriver(&drv_sb);
  1074.     MD_RegisterDriver(&drv_gus);
  1075.  
  1076.     MD_RegisterPlayer(tickhandler);
  1077.     mp_loop=1;
  1078.     mp_volume=0;
  1079.  
  1080.     // initialize sound card
  1081.     if(!MD_Init())
  1082.     {
  1083.         printf("\nMusic Driver error: %s.\n",myerr);
  1084.         return;
  1085.     }
  1086.  
  1087.     printf( "\nUsing %s for %d bit %s %s sound at %u Hz\n\n",
  1088.            md_driver->Name,
  1089.            (md_mode&DMODE_16BITS) ? 16:8,
  1090.            (md_mode&DMODE_INTERP) ? "interpolated":"normal",
  1091.            (md_mode&DMODE_STEREO) ? "stereo":"mono",
  1092.            md_mixfreq );
  1093.     mf = ML_LoadFN( "ponder.uni" );
  1094.     // didn't work, exit
  1095.     if( mf == NULL )
  1096.     {
  1097.         printf( "MikMod Error: %s\n", myerr );
  1098.         exit(0);
  1099.     }
  1100.     // initialize modplayer to play this module
  1101.     MP_Init(mf);
  1102.     md_numchn=mf->numchn;
  1103.     // End mikmod stuff /////////////////////////////////////////////////////
  1104.  
  1105.     // GO!!!
  1106.     SetVidMode( 0x13 );
  1107.     if( SCREEN_WIDTH == 256 ) SetLiketMode();
  1108.     SetPal( skypal );
  1109.     GetPalette( pal );
  1110.  
  1111.     // fade in to "an"
  1112.     DrawText( "an", (BUF_WIDTH - (28*2))/2, (BUF_HEIGHT - (40))/2, buf1 );
  1113.     WaitRetrace();
  1114.     ShowPic( buf1 );
  1115.     CopyPal( pal, skypal );
  1116.     while( !FadeIn( pal ) ){ }
  1117.  
  1118.     // start playing the module:
  1119.     MD_PlayStart();
  1120.  
  1121.     // fade out
  1122.     CopyPal( pal, skypal );
  1123.     while( !FadeOut( pal ) ){ FadeMusicIn(); MD_Update(); }
  1124.  
  1125.     // fade in to "Apex"
  1126.     CopyPal( pal, ponderpal );
  1127.     ShowPic( ponderpic );
  1128.     while( !FadeIn( pal ) ){ FadeMusicIn(); MD_Update(); }
  1129.  
  1130.     // delay just 3/4 of a sec or so:
  1131.     for( count = 0; count < 38; count++ )
  1132.     {
  1133.         FadeMusicIn();
  1134.         MD_Update();
  1135.         WaitRetrace();
  1136.         WaitNoRetrace();
  1137.     }
  1138.  
  1139.     // fade out
  1140.     GetPalette( pal );
  1141.     while( !FadeOut( pal ) ){ FadeMusicIn(); MD_Update(); }
  1142.  
  1143.     // fade to "production"
  1144.     ClearBuf( buf1, BUF_WIDTH* BUF_HEIGHT );
  1145.     DrawText( "production", (BUF_WIDTH - (AVG_CHAR_WIDTH*10))/2,
  1146.         (BUF_HEIGHT - (40))/2, buf1 );
  1147.     WaitRetrace();
  1148.     ShowPic( buf1 );
  1149.     CopyPal( pal, skypal );
  1150.     while( !FadeIn( pal ) ){ MD_Update(); }
  1151.  
  1152.     // fade to black
  1153.     GetPalette( pal );
  1154.     while( !FadeOut( pal ) ){ MD_Update(); }
  1155.  
  1156.     /////////////////////////////////////////////////////////////////////////
  1157.     // TUNNEL FADES IN AND "PONDER" APPEARS
  1158.     /////////////////////////////////////////////////////////////////////////
  1159.     x_off = 0;
  1160.     y_off = 0;
  1161.     CopyPal( pal, skypal );
  1162.     done = 0;
  1163.     while( !done )
  1164.     {
  1165.         // draw the tube:
  1166.         for( row = 0; row < BUF_HEIGHT; row++ )
  1167.         {
  1168.             for( col = 0; col < BUF_WIDTH; col++ )
  1169.             {
  1170.                 offs = row * BUF_WIDTH + col;
  1171.                 x = tube_x[offs];
  1172.                 y = tube_y[offs];
  1173.                 x += x_off;
  1174.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1175.             }
  1176.         }
  1177.         MD_Update();
  1178.         done = FadeIn( pal );
  1179.         ShowPic( buf1 );
  1180.         x_off += 3;
  1181.     }
  1182.     // if sound volume not max, set it to max:
  1183.     if( mp_volume != 100 ) mp_volume = 100;
  1184.     // "ponder"
  1185.     for( count = 0; count < 128; count++ )
  1186.     {
  1187.         // draw the tube:
  1188.         for( row = 0; row < BUF_HEIGHT; row++ )
  1189.         {
  1190.             for( col = 0; col < BUF_WIDTH; col++ )
  1191.             {
  1192.                 offs = row * BUF_WIDTH + col;
  1193.                 x = tube_x[offs];
  1194.                 y = tube_y[offs];
  1195.                 x += x_off;
  1196.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1197.             }
  1198.         }
  1199.         DrawText( "ponder", (BUF_WIDTH - (AVG_CHAR_WIDTH*6))/2,
  1200.             (BUF_HEIGHT - (40))/2, buf1 );
  1201.         MD_Update();
  1202.         WaitRetrace();
  1203.         ShowPic( buf1 );
  1204.         x_off += 3;
  1205.     }
  1206.  
  1207.     /////////////////////////////////////////////////////////////////////////
  1208.     // "SUCTION POINT" EFFECT:
  1209.     /////////////////////////////////////////////////////////////////////////
  1210.     x_off = 0;
  1211.     y_off = 0;
  1212.     for( count = 0; count < 75; count++ )
  1213.     {
  1214.         // draw the tube:
  1215.         for( row = 0; row < BUF_HEIGHT; row++ )
  1216.         {
  1217.             for( col = 0; col < BUF_WIDTH; col++ )
  1218.             {
  1219.                 offs = row * BUF_WIDTH + col;
  1220.                 x = radii2[offs];
  1221.                 y = circ_y[offs];
  1222.                 x += x_off;
  1223.                 buf1[offs] = tube_pic[y * 256 + x];
  1224.             }
  1225.         }
  1226.         MD_Update();
  1227.         WaitRetrace();
  1228.         ShowPic( buf1 );
  1229.         x_off += 3;
  1230.     }
  1231.     // "what do you think"
  1232.     for( count = 0; count < 50; count++ )
  1233.     {
  1234.         // draw the tube:
  1235.         for( row = 0; row < BUF_HEIGHT; row++ )
  1236.         {
  1237.             for( col = 0; col < BUF_WIDTH; col++ )
  1238.             {
  1239.                 offs = row * BUF_WIDTH + col;
  1240.                 x = radii2[offs];
  1241.                 y = circ_y[offs];
  1242.                 x += x_off;
  1243.                 buf1[offs] = tube_pic[y * 256 + x];
  1244.             }
  1245.         }
  1246.         DrawText( "what do you", 0, 60, buf1 );
  1247.         DrawText( "think", 150, 130, buf1 );
  1248.         MD_Update();
  1249.         WaitRetrace();
  1250.         ShowPic( buf1 );
  1251.         x_off += 3;
  1252.     }
  1253.     for( count = 0; count < 50; count++ )
  1254.     {
  1255.         // draw the tube:
  1256.         for( row = 0; row < BUF_HEIGHT; row++ )
  1257.         {
  1258.             for( col = 0; col < BUF_WIDTH; col++ )
  1259.             {
  1260.                 offs = row * BUF_WIDTH + col;
  1261.                 x = radii2[offs];
  1262.                 y = circ_y[offs];
  1263.                 x += x_off;
  1264.                 buf1[offs] = tube_pic[y * 256 + x];
  1265.             }
  1266.         }
  1267.         DrawText( "happens", (BUF_WIDTH - (AVG_CHAR_WIDTH*6))/2,
  1268.             (BUF_HEIGHT - (40))/2, buf1 );
  1269.         MD_Update();
  1270.         WaitRetrace();
  1271.         ShowPic( buf1 );
  1272.         x_off += 3;
  1273.     }
  1274.     WaitRetrace();
  1275.     for( count = 0; count < 50; count++ )
  1276.     {
  1277.         // draw the tube:
  1278.         for( row = 0; row < BUF_HEIGHT; row++ )
  1279.         {
  1280.             for( col = 0; col < BUF_WIDTH; col++ )
  1281.             {
  1282.                 offs = row * BUF_WIDTH + col;
  1283.                 x = radii2[offs];
  1284.                 y = circ_y[offs];
  1285.                 x += x_off;
  1286.                 buf1[offs] = tube_pic[y * 256 + x];
  1287.             }
  1288.         }
  1289.         DrawText( "when you", (BUF_WIDTH - (AVG_CHAR_WIDTH*8))/2,
  1290.             (BUF_HEIGHT - (40))/2, buf1 );
  1291.         DrawText( "die?", (BUF_WIDTH - (AVG_CHAR_WIDTH*4))/2, 116, buf1 );
  1292.         MD_Update();
  1293.         WaitRetrace();
  1294.         ShowPic( buf1 );
  1295.         x_off += 3;
  1296.     }
  1297.  
  1298.     /////////////////////////////////////////////////////////////////////////
  1299.     // FLASH SKULL PIC:
  1300.     /////////////////////////////////////////////////////////////////////////
  1301.     WaitRetrace();
  1302.     SetPal( skullpal );
  1303.     ShowPic( skullpic );
  1304.     // wait a fifth of a sec or so:
  1305.     for( count = 0; count < 10; count++ )
  1306.     {
  1307.         MD_Update();
  1308.         WaitRetrace();
  1309.         WaitNoRetrace();
  1310.     }
  1311.  
  1312.  
  1313.     /////////////////////////////////////////////////////////////////////////
  1314.     // FIRE TUNNEL:
  1315.     /////////////////////////////////////////////////////////////////////////
  1316.     ClearBuf( screen, SCREEN_WIDTH * SCREEN_HEIGHT );
  1317.     WaitRetrace();
  1318.     SetPal( firepal );
  1319.     GetPalette( pal );
  1320.     while( !FadeIn( pal ) )
  1321.     {
  1322.         FadeIn( pal );
  1323.         // draw the tube:
  1324.         for( row = 0; row < BUF_HEIGHT; row++ )
  1325.         {
  1326.             for( col = 0; col < BUF_WIDTH; col++ )
  1327.             {
  1328.                 offs = row * BUF_WIDTH + col;
  1329.                 x = tube_x[offs];
  1330.                 y = tube_y[offs];
  1331.                 x += x_off;
  1332.                 y += y_off;
  1333.                 buf1[offs] = tube_pic[y * 256 + x] + (radii3[offs]);
  1334.             }
  1335.         }
  1336.         DrawText( "do you go to", 3, (BUF_HEIGHT - (40))/2,
  1337.                  buf1 );
  1338.         DrawText( "hell?", (BUF_WIDTH - (AVG_CHAR_WIDTH*5))/2, 116, buf1 );
  1339.         MD_Update();
  1340.         WaitRetrace();
  1341.         ShowPic( buf1 );
  1342.         x_off += 6;
  1343.     }
  1344.  
  1345.     /////////////////////////////////////////////////////////////////////////
  1346.     // DOUBLE SWIRLY:
  1347.     /////////////////////////////////////////////////////////////////////////
  1348.     x_off2 = 128;
  1349.     y_off2 = 128;
  1350.     x_off = 0;
  1351.     y_off = 0;
  1352.     WaitRetrace();
  1353.     ClearBuf( screen, SCREEN_WIDTH * SCREEN_HEIGHT );
  1354.     SetPal( skypal );
  1355.     for( count = 0; count < 75; count++ )
  1356.     {
  1357.         // draw the tube:
  1358.         for( row = 0; row < BUF_HEIGHT; row +=2 )
  1359.         {
  1360.             for( col = 0; col < BUF_WIDTH; col++ )
  1361.             {
  1362.                 offs = row * BUF_WIDTH + col;
  1363.                 x = tube_x[offs];
  1364.                 y = tube_y[offs]+(xGetSin(radii2[offs]*2)>>11);
  1365.                 x += x_off;
  1366.                 y += y_off;
  1367.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1368.             }
  1369.         }
  1370.         for( row = 1; row < BUF_HEIGHT; row +=2 )
  1371.         {
  1372.             for( col = 0; col < BUF_WIDTH; col++ )
  1373.             {
  1374.                 offs = row * BUF_WIDTH + col;
  1375.                 x = tube_x[offs];
  1376.                 y = tube_y[offs]+(xGetSin(radii2[offs]*2)>>11);
  1377.                 x -= x_off2;
  1378.                 y -= y_off2;
  1379.                 buf1[offs] = tube_pic[x * 256 + y] + (radii[offs]*16);
  1380.             }
  1381.         }
  1382.         MD_Update();
  1383.         WaitRetrace();
  1384.         ShowPic( buf1 );
  1385.         x_off += 3;
  1386.         y_off += 3;
  1387.         x_off2 +=3;
  1388.         y_off2 = (xGetSin( x_off2 ) >> 10);
  1389.         y_off2 += 3;
  1390.     }
  1391.  
  1392.     // "or heaven?"
  1393.     for( count = 0; count < 50; count++ )
  1394.     {
  1395.         // draw the tube:
  1396.         for( row = 0; row < BUF_HEIGHT; row +=2 )
  1397.         {
  1398.             for( col = 0; col < BUF_WIDTH; col++ )
  1399.             {
  1400.                 offs = row * BUF_WIDTH + col;
  1401.                 x = tube_x[offs];
  1402.                 y = tube_y[offs]+(xGetSin(radii2[offs]*2)>>11);
  1403.                 x += x_off;
  1404.                 y += y_off;
  1405.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1406.             }
  1407.         }
  1408.         for( row = 1; row < BUF_HEIGHT; row +=2 )
  1409.         {
  1410.             for( col = 0; col < BUF_WIDTH; col++ )
  1411.             {
  1412.                 offs = row * BUF_WIDTH + col;
  1413.                 x = tube_x[offs];
  1414.                 y = tube_y[offs]+(xGetSin(radii2[offs]*2)>>11);
  1415.                 x -= x_off2;
  1416.                 y -= y_off2;
  1417.                 buf1[offs] = tube_pic[x * 256 + y] + (radii[offs]*16);
  1418.             }
  1419.         }
  1420.         DrawText( "or", 30, 40, buf1 );
  1421.         DrawText( "heaven?", 80, 105, buf1 );
  1422.         MD_Update();
  1423.         WaitRetrace();
  1424.         ShowPic( buf1 );
  1425.         x_off += 3;
  1426.         y_off += 3;
  1427.         x_off2 +=3;
  1428.         y_off2 = (xGetSin( x_off2 ) >> 10);
  1429.         y_off2 += 3;
  1430.     }
  1431.  
  1432.     /////////////////////////////////////////////////////////////////////////
  1433.     // RAYS SHOOT OUT
  1434.     /////////////////////////////////////////////////////////////////////////
  1435.     x_off = 0;
  1436.     y_off = 0;
  1437.     for( count = 0; count < 75; count++ )
  1438.     {
  1439.         // draw the tube:
  1440.         for( row = 0; row < BUF_HEIGHT; row++ )
  1441.         {
  1442.             for( col = 0; col < BUF_WIDTH; col++ )
  1443.             {
  1444.                 offs = row * BUF_WIDTH + col;
  1445.                 x = circ_x[offs];
  1446.                 y = circ_y[offs];
  1447.                 x += x_off;
  1448.                 buf1[offs] = tube_pic[y * 256 + x];
  1449.             }
  1450.         }
  1451.         MD_Update();
  1452.         WaitRetrace();
  1453.         ShowPic( buf1 );
  1454.         x_off += 3;
  1455.     }
  1456.     // "Do you see god?"
  1457.     for( count = 0; count < 50; count++ )
  1458.     {
  1459.         // draw the tube:
  1460.         for( row = 0; row < BUF_HEIGHT; row++ )
  1461.         {
  1462.             for( col = 0; col < BUF_WIDTH; col++ )
  1463.             {
  1464.                 offs = row * BUF_WIDTH + col;
  1465.                 x = circ_x[offs];
  1466.                 y = circ_y[offs];
  1467.                 x += x_off;
  1468.                 buf1[offs] = tube_pic[y * 256 + x];
  1469.             }
  1470.         }
  1471.         DrawText( "do you see", 10, 70, buf1 );
  1472.         DrawText( "god?", 100, 120, buf1 );
  1473.         MD_Update();
  1474.         WaitRetrace();
  1475.         ShowPic( buf1 );
  1476.         x_off += 3;
  1477.     }
  1478.     // "or do you see"
  1479.     for( count = 0; count < 50; count++ )
  1480.     {
  1481.         // draw the tube:
  1482.         for( row = 0; row < BUF_HEIGHT; row++ )
  1483.         {
  1484.             for( col = 0; col < BUF_WIDTH; col++ )
  1485.             {
  1486.                 offs = row * BUF_WIDTH + col;
  1487.                 x = circ_x[offs];
  1488.                 y = circ_y[offs];
  1489.                 x += x_off;
  1490.                 buf1[offs] = tube_pic[y * 256 + x];
  1491.             }
  1492.         }
  1493.         DrawText( "or", 10, 40, buf1 );
  1494.         DrawText( "do you see", 10, 100, buf1 );
  1495.         MD_Update();
  1496.         WaitRetrace();
  1497.         ShowPic( buf1 );
  1498.         x_off += 3;
  1499.     }
  1500.  
  1501.     /////////////////////////////////////////////////////////////////////////
  1502.     // BLANK PAGE:
  1503.     /////////////////////////////////////////////////////////////////////////
  1504.     ClearBuf( buf1, BUF_WIDTH * BUF_HEIGHT );
  1505.     DrawText( "nothing?", (BUF_WIDTH - (AVG_CHAR_WIDTH*8))/2,
  1506.         (BUF_HEIGHT - 40)/2, buf1 );
  1507.     ShowPic( buf1 );
  1508.     // fade to black
  1509.     GetPalette( pal );
  1510.     while( !FadeOut( pal ) ){ MD_Update(); }
  1511.  
  1512.  
  1513.     /////////////////////////////////////////////////////////////////////////
  1514.     // REVERSING SWIRLER
  1515.     /////////////////////////////////////////////////////////////////////////
  1516.     WaitRetrace();
  1517.     ClearBuf( screen, SCREEN_WIDTH * SCREEN_HEIGHT );
  1518.     SetPal( skypal );
  1519.     y_off = 0;
  1520.     x_off = 0;
  1521.     for( count = 0; count < 75; count++ )
  1522.     {
  1523.         // draw the tube:
  1524.         for( row = 0; row < BUF_HEIGHT; row++ )
  1525.         {
  1526.             for( col = 0; col < BUF_WIDTH; col++ )
  1527.             {
  1528.                 offs = row * BUF_WIDTH + col;
  1529.                 x = tube_x[offs];
  1530.                 y = tube_y[offs]+(xGetSin(radii2[offs]*2)>>11);
  1531.                 x += x_off;
  1532.                 y += y_off;
  1533.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1534.             }
  1535.         }
  1536.         MD_Update();
  1537.         WaitRetrace();
  1538.         ShowPic( buf1 );
  1539.         x_off += 3;
  1540.         y_off = (xGetSin( x_off ) >> 10);
  1541.     }
  1542.     // "what do you see"
  1543.     for( count = 0; count < 50; count++ )
  1544.     {
  1545.         // draw the tube:
  1546.         for( row = 0; row < BUF_HEIGHT; row++ )
  1547.         {
  1548.             for( col = 0; col < BUF_WIDTH; col++ )
  1549.             {
  1550.                 offs = row * BUF_WIDTH + col;
  1551.                 x = tube_x[offs];
  1552.                 y = tube_y[offs]+(xGetSin(radii2[offs]*2)>>11);
  1553.                 x += x_off;
  1554.                 y += y_off;
  1555.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1556.             }
  1557.         }
  1558.         DrawText( "what do you", 10, 30, buf1 );
  1559.         DrawText( "see", 160, 130, buf1 );
  1560.         MD_Update();
  1561.         WaitRetrace();
  1562.         ShowPic( buf1 );
  1563.         x_off += 3;
  1564.         y_off = (xGetSin( x_off ) >> 10);
  1565.     }
  1566.  
  1567.  
  1568.     /////////////////////////////////////////////////////////////////////////
  1569.     // DOUBLE BITMAP ROTATOR/SCALER
  1570.     /////////////////////////////////////////////////////////////////////////
  1571.     mangle theta;
  1572.     for( theta = 0; theta < MANGLE_360>>2; theta++ )
  1573.     {
  1574.         RotateBmp( buf1, tube_pic, theta, xGetSin( theta ) / 2 +0x9000 );
  1575.         MD_Update();
  1576.         WaitRetrace();
  1577.         ShowPic( buf1 );
  1578.     }
  1579.     for ( ; theta < MANGLE_360>>1; theta++ )
  1580.     {
  1581.         RotateBmp( buf1, tube_pic, theta, xGetSin( theta ) / 2 +0x9000 );
  1582.         DrawText( "in your", 10, 60, buf1 );
  1583.         DrawText( "dreams?", 90, 100, buf1 );
  1584.         MD_Update();
  1585.         WaitRetrace();
  1586.         ShowPic( buf1 );
  1587.     }
  1588.     for ( ; theta < 192; theta++ )
  1589.     {
  1590.         RotateBmp( buf1, tube_pic, theta, xGetSin( theta ) / 2 +0x9000 );
  1591.         MD_Update();
  1592.         WaitRetrace();
  1593.         ShowPic( buf1 );
  1594.     }
  1595.     for ( ; theta < 192+50; theta++ )
  1596.     {
  1597.         RotateBmp( buf1, tube_pic, theta, xGetSin( theta ) / 2 +0x9000 );
  1598.         DrawText( "are you mad", 18, (BUF_HEIGHT - 40)/2,
  1599.             buf1 );
  1600.         MD_Update();
  1601.         WaitRetrace();
  1602.         ShowPic( buf1 );
  1603.     }
  1604.  
  1605.  
  1606.     /////////////////////////////////////////////////////////////////////////
  1607.     // flash eyeball pic
  1608.     /////////////////////////////////////////////////////////////////////////
  1609.     WaitRetrace();
  1610.     SetPal( eyepal );
  1611.     ShowPic( eyepic );
  1612.     // wait a fifth of a sec or so:
  1613.     for( count = 0; count < 10; count++ )
  1614.     {
  1615.         MD_Update();
  1616.         WaitRetrace();
  1617.         WaitNoRetrace();
  1618.     }
  1619.  
  1620.  
  1621.     /////////////////////////////////////////////////////////////////////////
  1622.     // DOUBLE U GHOSTLY TUNNEL
  1623.     /////////////////////////////////////////////////////////////////////////
  1624.     y_off = 0;
  1625.     unsigned char yoff2 = 0;
  1626.     WaitRetrace();
  1627.     ClearBuf( screen, SCREEN_WIDTH * SCREEN_HEIGHT );
  1628.     SetPal( skypal );
  1629.     for( count = 0; count < 75; count++ )
  1630.     {
  1631.         // draw the tube:
  1632.         for( row = 0; row < BUF_HEIGHT; row += 2 )
  1633.         {
  1634.             for( col = 0; col < BUF_WIDTH; col++ )
  1635.             {
  1636.                 offs = row * BUF_WIDTH + col;
  1637.                 x = tube_x[offs];
  1638.                 y = tube_y[offs];
  1639.                 x += x_off;
  1640.                 y += y_off;
  1641.                 y_off--;
  1642.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1643.             }
  1644.         }
  1645.         for( row = 1; row < BUF_HEIGHT; row += 2 )
  1646.         {
  1647.             for( col = 0; col < BUF_WIDTH; col++ )
  1648.             {
  1649.                 offs = row * BUF_WIDTH + col;
  1650.                 x = tube_x[offs];
  1651.                 y = tube_y[offs];
  1652.                 x += x_off;
  1653.                 y += yoff2;
  1654.                 yoff2++;
  1655.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1656.             }
  1657.         }
  1658.         MD_Update();
  1659.         WaitRetrace();
  1660.         ShowPic( buf1 );
  1661.         x_off += 3;
  1662.         y_off--;
  1663.         yoff2++;
  1664.     }
  1665.     // "to see such things"
  1666.     for( count = 0; count < 75; count++ )
  1667.     {
  1668.         // draw the tube:
  1669.         for( row = 0; row < BUF_HEIGHT; row += 2 )
  1670.         {
  1671.             for( col = 0; col < BUF_WIDTH; col++ )
  1672.             {
  1673.                 offs = row * BUF_WIDTH + col;
  1674.                 x = tube_x[offs];
  1675.                 y = tube_y[offs];
  1676.                 x += x_off;
  1677.                 y += y_off;
  1678.                 y_off--;
  1679.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1680.             }
  1681.         }
  1682.         for( row = 1; row < BUF_HEIGHT; row += 2 )
  1683.         {
  1684.             for( col = 0; col < BUF_WIDTH; col++ )
  1685.             {
  1686.                 offs = row * BUF_WIDTH + col;
  1687.                 x = tube_x[offs];
  1688.                 y = tube_y[offs];
  1689.                 x += x_off;
  1690.                 y += yoff2;
  1691.                 yoff2++;
  1692.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1693.             }
  1694.         }
  1695.         DrawText( "to see", 20, 20, buf1 );
  1696.         DrawText( "such things?", 16, 120, buf1 );
  1697.         MD_Update();
  1698.         WaitRetrace();
  1699.         ShowPic( buf1 );
  1700.         x_off += 3;
  1701.         y_off--;
  1702.         yoff2++;
  1703.     }
  1704.  
  1705.     /////////////////////////////////////////////////////////////////////////
  1706.     // SKY WITH CLOUDS
  1707.     /////////////////////////////////////////////////////////////////////////
  1708.     WaitRetrace();
  1709.     SetPaletteSpread( 0, 0, 63, 63, 63, 63, 0, 127 );
  1710.     GetPalette( pal );
  1711.     ClearBuf( buf1, BUF_WIDTH * BUF_HEIGHT );
  1712.     long dx, dy;
  1713.     int column, angle;
  1714.     int i;
  1715.     int skyHoriz = BUF_HEIGHT-1;
  1716.     unsigned char *d;
  1717.  
  1718.     for( count = 0; count < 63; count++ )
  1719.     {
  1720.         xOrg += speed * COS( Yaw ) >> 8;
  1721.         yOrg += speed * SIN( Yaw ) >> 8;
  1722.  
  1723.         for( column = 0; column < BUF_WIDTH; column++ )
  1724.         {
  1725.             angle = (ViewAngle * (BUF_WIDTH- column * 2)) / BUF_WIDTH;
  1726.             dx = COS( Yaw + angle) << (RADIX - 16);
  1727.             dy = SIN( Yaw + angle) << (RADIX - 16);
  1728.  
  1729.             CastSkyRay( column, skyHoriz, dx, dy );
  1730.         }
  1731.  
  1732.         FadeIn( pal );
  1733.  
  1734.         // copy the buffer to the screen:
  1735.         MD_Update();
  1736.         WaitRetrace();
  1737.         ShowPic( buf1 );
  1738.     }
  1739.     // "do clouds form images"
  1740.     for( count = 0; count < 50; count++ )
  1741.     {
  1742.         xOrg += speed * COS( Yaw ) >> 8;
  1743.         yOrg += speed * SIN( Yaw ) >> 8;
  1744.  
  1745.         for( column = 0; column < BUF_WIDTH; column++ )
  1746.         {
  1747.             angle = (ViewAngle * (BUF_WIDTH- column * 2)) / BUF_WIDTH;
  1748.             dx = COS( Yaw + angle) << (RADIX - 16);
  1749.             dy = SIN( Yaw + angle) << (RADIX - 16);
  1750.  
  1751.             CastSkyRay( column, skyHoriz, dx, dy );
  1752.         }
  1753.  
  1754.         // copy the buffer to the screen:
  1755.         DrawText( "do clouds", 30, 30, buf1 );
  1756.         DrawText( "form images", 20, 110, buf1 );
  1757.         MD_Update();
  1758.         WaitRetrace();
  1759.         ShowPic( buf1 );
  1760.     }
  1761.     // "behind your eyes"
  1762.     for( count = 0; count < 50; count++ )
  1763.     {
  1764.         xOrg += speed * COS( Yaw ) >> 8;
  1765.         yOrg += speed * SIN( Yaw ) >> 8;
  1766.  
  1767.         for( column = 0; column < BUF_WIDTH; column++ )
  1768.         {
  1769.             angle = (ViewAngle * (BUF_WIDTH- column * 2)) / BUF_WIDTH;
  1770.             dx = COS( Yaw + angle) << (RADIX - 16);
  1771.             dy = SIN( Yaw + angle) << (RADIX - 16);
  1772.  
  1773.             CastSkyRay( column, skyHoriz, dx, dy );
  1774.         }
  1775.  
  1776.         // copy the buffer to the screen:
  1777.         DrawText( "behind", 40, 40, buf1 );
  1778.         DrawText( "your eyes?", 20, 110, buf1 );
  1779.         MD_Update();
  1780.         WaitRetrace();
  1781.         ShowPic( buf1 );
  1782.     }
  1783.     /////////////////////////////////////////////////////////////////////////
  1784.     // flash eyeball pic
  1785.     /////////////////////////////////////////////////////////////////////////
  1786.     WaitRetrace();
  1787.     SetPal( eyepal );
  1788.     ShowPic( eyepic );
  1789.     // wait a fifth of a sec or so:
  1790.     for( count = 0; count < 10; count++ )
  1791.     {
  1792.         MD_Update();
  1793.         WaitRetrace();
  1794.         WaitNoRetrace();
  1795.     }
  1796.     // fade sky...
  1797.     ClearBuf( screen, SCREEN_WIDTH * SCREEN_HEIGHT );
  1798.     WaitRetrace();
  1799.     SetPaletteSpread( 0, 0, 63, 63, 63, 63, 0, 127 );
  1800.     GetPalette( pal );
  1801.     for( count = 0; count < 50; count++ )
  1802.     {
  1803.         xOrg += speed * COS( Yaw ) >> 8;
  1804.         yOrg += speed * SIN( Yaw ) >> 8;
  1805.  
  1806.         for( column = 0; column < BUF_WIDTH; column++ )
  1807.         {
  1808.             angle = (ViewAngle * (BUF_WIDTH- column * 2)) / BUF_WIDTH;
  1809.             dx = COS( Yaw + angle) << (RADIX - 16);
  1810.             dy = SIN( Yaw + angle) << (RADIX - 16);
  1811.  
  1812.             CastSkyRay( column, skyHoriz, dx, dy );
  1813.         }
  1814.  
  1815.         // fade to black
  1816.         FadeOut( pal );
  1817.         FadeOut( pal );
  1818.  
  1819.         // copy the buffer to the screen:
  1820.         MD_Update();
  1821.         WaitRetrace();
  1822.         ShowPic( buf1 );
  1823.     }
  1824.  
  1825.     /////////////////////////////////////////////////////////////////////////
  1826.     // WATERY GRAVE:
  1827.     /////////////////////////////////////////////////////////////////////////
  1828.     ClearBuf( screen, SCREEN_WIDTH * SCREEN_HEIGHT );
  1829.     WaitRetrace();
  1830.     SetPal( skypal2 );
  1831.     y_off = 0;
  1832.     for( count = 0; count < 75; count++ )
  1833.     {
  1834.         // draw the tube:
  1835.         for( row = 0; row < BUF_HEIGHT; row++ )
  1836.         {
  1837.             for( col = 0; col < BUF_WIDTH; col++ )
  1838.             {
  1839.                 offs = row * BUF_WIDTH + col;
  1840.                 x = tube_x[offs];
  1841.                 y = tube_y[offs]+(xGetSin(radii3[offs]*16)>>10);
  1842.                 x += x_off;
  1843.                 buf1[offs] = tube_pic[y * 256 + x] + (radii3[offs]*16);
  1844.             }
  1845.         }
  1846.         MD_Update();
  1847.         WaitRetrace();
  1848.         ShowPic( buf1 );
  1849.         x_off += 3;
  1850.     }
  1851.     // "if you were drowning"
  1852.     for( count = 0; count < 75; count++ )
  1853.     {
  1854.         // draw the tube:
  1855.         for( row = 0; row < BUF_HEIGHT; row++ )
  1856.         {
  1857.             for( col = 0; col < BUF_WIDTH; col++ )
  1858.             {
  1859.                 offs = row * BUF_WIDTH + col;
  1860.                 x = tube_x[offs];
  1861.                 y = tube_y[offs]+(xGetSin(radii3[offs]*16)>>10);
  1862.                 x += x_off;
  1863.                 buf1[offs] = tube_pic[y * 256 + x] + (radii3[offs]*16);
  1864.             }
  1865.         }
  1866.         DrawText( "if you were", 25, 45, buf1 );
  1867.         DrawText( "drowning", 80, 120, buf1 );
  1868.         MD_Update();
  1869.         WaitRetrace();
  1870.         ShowPic( buf1 );
  1871.         x_off += 3;
  1872.     }
  1873.  
  1874.     /////////////////////////////////////////////////////////////////////////
  1875.     // SIN SWIRLER:
  1876.     /////////////////////////////////////////////////////////////////////////
  1877.     y_off = 0;
  1878.     for( count = 0; count < 75; count++ )
  1879.     {
  1880.         // draw the tube:
  1881.         for( row = 0; row < BUF_HEIGHT; row++ )
  1882.         {
  1883.             for( col = 0; col < BUF_WIDTH; col++ )
  1884.             {
  1885.                 offs = row * BUF_WIDTH + col;
  1886.                 x = tube_x[offs];
  1887.                 y = tube_y[offs]+(xGetSin(radii2[offs])>>8);
  1888.                 x += x_off;
  1889.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1890.             }
  1891.         }
  1892.         MD_Update();
  1893.         WaitRetrace();
  1894.         ShowPic( buf1 );
  1895.         x_off += 3;
  1896.     }
  1897.     // "would you cry?"
  1898.     for( count = 0; count < 50; count++ )
  1899.     {
  1900.         // draw the tube:
  1901.         for( row = 0; row < BUF_HEIGHT; row++ )
  1902.         {
  1903.             for( col = 0; col < BUF_WIDTH; col++ )
  1904.             {
  1905.                 offs = row * BUF_WIDTH + col;
  1906.                 x = tube_x[offs];
  1907.                 y = tube_y[offs]+(xGetSin(radii2[offs])>>8);
  1908.                 x += x_off;
  1909.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1910.             }
  1911.         }
  1912.         DrawText( "would you", 60, 40, buf1 );
  1913.         DrawText( "cry?", 20, 100, buf1 );
  1914.         MD_Update();
  1915.         WaitRetrace();
  1916.         ShowPic( buf1 );
  1917.         x_off += 3;
  1918.     }
  1919.  
  1920.     /////////////////////////////////////////////////////////////////////////
  1921.     // SKY + ROTATING CLOUDS
  1922.     /////////////////////////////////////////////////////////////////////////
  1923.     WaitRetrace();
  1924.     SetPaletteSpread( 0, 0, 63, 63, 63, 63, 0, 127 );
  1925.     for( theta = 0; theta < MANGLE_360>>2; theta++ )
  1926.     {
  1927.         xOrg += speed * COS( Yaw ) >> 8;
  1928.         yOrg += speed * SIN( Yaw ) >> 8;
  1929.  
  1930.         for( column = 0; column < BUF_WIDTH; column++ )
  1931.         {
  1932.             angle = (ViewAngle * (BUF_WIDTH- column * 2)) / BUF_WIDTH;
  1933.             dx = COS( Yaw + angle) << (RADIX - 16);
  1934.             dy = SIN( Yaw + angle) << (RADIX - 16);
  1935.  
  1936.             CastSkyRay2( column, skyHoriz, dx, dy );
  1937.             CastSkyRay3( column, skyHoriz, dy, dx );
  1938.         }
  1939.  
  1940.         // copy the buffer to the screen:
  1941.         MD_Update();
  1942.         WaitRetrace();
  1943.         ShowPic( buf1 );
  1944.     }
  1945.     // "if you watched yourself"
  1946.     for( theta = 0; theta < MANGLE_360>>2; theta++ )
  1947.     {
  1948.         xOrg += speed * COS( Yaw ) >> 8;
  1949.         yOrg += speed * SIN( Yaw ) >> 8;
  1950.  
  1951.         for( column = 0; column < BUF_WIDTH; column++ )
  1952.         {
  1953.             angle = (ViewAngle * (BUF_WIDTH- column * 2)) / BUF_WIDTH;
  1954.             dx = COS( Yaw + angle) << (RADIX - 16);
  1955.             dy = SIN( Yaw + angle) << (RADIX - 16);
  1956.  
  1957.             CastSkyRay2( column, skyHoriz, dx, dy );
  1958.             CastSkyRay3( column, skyHoriz, dy, dx );
  1959.         }
  1960.  
  1961.         // copy the buffer to the screen:
  1962.         DrawText( "if", 20, 20, buf1 );
  1963.         DrawText( "you watched", 10, 70, buf1 );
  1964.         DrawText( "yourself", 40, 120, buf1 );
  1965.         MD_Update();
  1966.         WaitRetrace();
  1967.         ShowPic( buf1 );
  1968.     }
  1969.  
  1970.     /////////////////////////////////////////////////////////////////////////
  1971.     // STATIC THING
  1972.     /////////////////////////////////////////////////////////////////////////
  1973.     WaitRetrace();
  1974.     ClearBuf( screen, SCREEN_WIDTH * SCREEN_HEIGHT );
  1975.     SetPal( skypal );
  1976.     y_off = 0;
  1977.     for( count = 0; count < 75; count++ )
  1978.     {
  1979.         // draw the tube:
  1980.         for( row = 0; row < BUF_HEIGHT; row++ )
  1981.         {
  1982.             for( col = 0; col < BUF_WIDTH; col++ )
  1983.             {
  1984.                 offs = row * BUF_WIDTH + col;
  1985.                 x = tube_x[offs];
  1986.                 y = tube_y[offs];
  1987.                 x += x_off;
  1988.                 y += y_off;
  1989.                 y_off += (xGetSin( x )>>13);
  1990.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  1991.             }
  1992.         }
  1993.         MD_Update();
  1994.         WaitRetrace();
  1995.         ShowPic( buf1 );
  1996.         x_off += 3;
  1997.     }
  1998.     // "die on tv"
  1999.     for( count = 0; count < 16; count++ )
  2000.     {
  2001.         // draw the tube:
  2002.         for( row = 0; row < BUF_HEIGHT; row++ )
  2003.         {
  2004.             for( col = 0; col < BUF_WIDTH; col++ )
  2005.             {
  2006.                 offs = row * BUF_WIDTH + col;
  2007.                 x = tube_x[offs];
  2008.                 y = tube_y[offs];
  2009.                 x += x_off;
  2010.                 y += y_off;
  2011.                 y_off += (xGetSin( x )>>13);
  2012.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  2013.             }
  2014.         }
  2015.         DrawText( "die on", (BUF_WIDTH - (20*6))/2, 40, buf1 );
  2016.         DrawText( "tv", (BUF_WIDTH - 40)/2, 112, buf1 );
  2017.         MD_Update();
  2018.         WaitRetrace();
  2019.         ShowPic( buf1 );
  2020.         x_off += 3;
  2021.     }
  2022.     /////////////////////////////////////////////////////////////////////////
  2023.     // FLASH SKULL PIC:
  2024.     /////////////////////////////////////////////////////////////////////////
  2025.     WaitRetrace();
  2026.     SetPal( skullpal );
  2027.     ShowPic( skullpic );
  2028.     // wait a fifth of a sec or so:
  2029.     for( count = 0; count < 10; count++ )
  2030.     {
  2031.         MD_Update();
  2032.         WaitRetrace();
  2033.         WaitNoRetrace();
  2034.     }
  2035.  
  2036.     WaitRetrace();
  2037.     ClearBuf( screen, SCREEN_WIDTH * SCREEN_HEIGHT );
  2038.     SetPal( skypal );
  2039.  
  2040.     for( count = 0; count < 16; count++ )
  2041.     {
  2042.         // draw the tube:
  2043.         for( row = 0; row < BUF_HEIGHT; row++ )
  2044.         {
  2045.             for( col = 0; col < BUF_WIDTH; col++ )
  2046.             {
  2047.                 offs = row * BUF_WIDTH + col;
  2048.                 x = tube_x[offs];
  2049.                 y = tube_y[offs];
  2050.                 x += x_off;
  2051.                 y += y_off;
  2052.                 y_off += (xGetSin( x )>>13);
  2053.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  2054.             }
  2055.         }
  2056.         DrawText( "die on", (BUF_WIDTH - (20*6))/2, 40, buf1 );
  2057.         DrawText( "tv", (BUF_WIDTH - 40)/2, 112, buf1 );
  2058.         MD_Update();
  2059.         WaitRetrace();
  2060.         ShowPic( buf1 );
  2061.         x_off += 3;
  2062.     }
  2063.  
  2064.     /////////////////////////////////////////////////////////////////////////
  2065.     // RAYS PLUS SWIRLY
  2066.     /////////////////////////////////////////////////////////////////////////
  2067.     x_off = 0;
  2068.     y_off = 0;
  2069.     for( count = 0; count < 75; count++ )
  2070.     {
  2071.         // draw the "rays"
  2072.         for( row = 0; row < BUF_HEIGHT; row += 2 )
  2073.         {
  2074.             for( col = 0; col < BUF_WIDTH; col++ )
  2075.             {
  2076.                 offs = row * BUF_WIDTH + col;
  2077.                 x = circ_x[offs];
  2078.                 y = circ_y[offs];
  2079.                 x += x_off;
  2080.                 buf1[offs] = tube_pic[y * 256 + x] + 128;
  2081.             }
  2082.         }
  2083.         // draw the tube:
  2084.         for( row = 1; row < BUF_HEIGHT; row += 2 )
  2085.         {
  2086.             for( col = 0; col < BUF_WIDTH; col++ )
  2087.             {
  2088.                 offs = row * BUF_WIDTH + col;
  2089.                 x = tube_x[offs];
  2090.                 y = tube_y[offs]+(xGetSin(radii2[offs])>>8);
  2091.                 x += x_off;
  2092.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  2093.             }
  2094.         }
  2095.         MD_Update();
  2096.         WaitRetrace();
  2097.         ShowPic( buf1 );
  2098.         x_off += 3;
  2099.     }
  2100.     // "would you think"
  2101.     for( count = 0; count < 50; count++ )
  2102.     {
  2103.         // draw the "rays"
  2104.         for( row = 0; row < BUF_HEIGHT; row += 2 )
  2105.         {
  2106.             for( col = 0; col < BUF_WIDTH; col++ )
  2107.             {
  2108.                 offs = row * BUF_WIDTH + col;
  2109.                 x = circ_x[offs];
  2110.                 y = circ_y[offs];
  2111.                 x += x_off;
  2112.                 buf1[offs] = tube_pic[y * 256 + x] + 128;
  2113.             }
  2114.         }
  2115.         // draw the tube:
  2116.         for( row = 1; row < BUF_HEIGHT; row += 2 )
  2117.         {
  2118.             for( col = 0; col < BUF_WIDTH; col++ )
  2119.             {
  2120.                 offs = row * BUF_WIDTH + col;
  2121.                 x = tube_x[offs];
  2122.                 y = tube_y[offs]+(xGetSin(radii2[offs])>>8);
  2123.                 x += x_off;
  2124.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  2125.             }
  2126.         }
  2127.         DrawText( "would you", 10, 20, buf1 );
  2128.         DrawText( "think", 20, 90, buf1 );
  2129.         MD_Update();
  2130.         WaitRetrace();
  2131.         ShowPic( buf1 );
  2132.         x_off += 3;
  2133.     }
  2134.     // "that was strange"
  2135.     for( count = 0; count < 50; count++ )
  2136.     {
  2137.         // draw the "rays"
  2138.         for( row = 0; row < BUF_HEIGHT; row += 2 )
  2139.         {
  2140.             for( col = 0; col < BUF_WIDTH; col++ )
  2141.             {
  2142.                 offs = row * BUF_WIDTH + col;
  2143.                 x = circ_x[offs];
  2144.                 y = circ_y[offs];
  2145.                 x += x_off;
  2146.                 buf1[offs] = tube_pic[y * 256 + x] + 128;
  2147.             }
  2148.         }
  2149.         // draw the tube:
  2150.         for( row = 1; row < BUF_HEIGHT; row += 2 )
  2151.         {
  2152.             for( col = 0; col < BUF_WIDTH; col++ )
  2153.             {
  2154.                 offs = row * BUF_WIDTH + col;
  2155.                 x = tube_x[offs];
  2156.                 y = tube_y[offs]+(xGetSin(radii2[offs])>>8);
  2157.                 x += x_off;
  2158.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  2159.             }
  2160.         }
  2161.         DrawText( "that", 20, 40, buf1 );
  2162.         DrawText( "was strange?", 20, 120, buf1 );
  2163.         MD_Update();
  2164.         WaitRetrace();
  2165.         ShowPic( buf1 );
  2166.         x_off += 3;
  2167.     }
  2168.  
  2169.     /////////////////////////////////////////////////////////////////////////
  2170.     // DOUBLE SWIRLING RAYS
  2171.     /////////////////////////////////////////////////////////////////////////
  2172.     WaitRetrace();
  2173.     SetPal( raypal );
  2174.     y_off = 0;
  2175.     for( count = 0; count < 75; count++ )
  2176.     {
  2177.         // draw the tube:
  2178.         for( row = 0; row < BUF_HEIGHT; row +=2 )
  2179.         {
  2180.             for( col = 0; col < BUF_WIDTH; col++ )
  2181.             {
  2182.                 offs = row * BUF_WIDTH + col;
  2183.                 x = circ_x[offs];
  2184.                 y = circ_y[offs]+(xGetSin(radii2[offs]*2)>>11);
  2185.                 x += x_off;
  2186.                 y += y_off;
  2187.                 buf1[offs] = tube_pic[y * 256 + x];
  2188.             }
  2189.         }
  2190.         // draw the tube:
  2191.         for( row = 1; row < BUF_HEIGHT; row += 2 )
  2192.         {
  2193.             for( col = 0; col < BUF_WIDTH; col++ )
  2194.             {
  2195.                 offs = row * BUF_WIDTH + col;
  2196.                 x = circ_x[offs];
  2197.                 y = circ_y[offs]+(xGetCos(radii2[offs]*2)>>11);
  2198.                 x -= x_off;
  2199.                 y -= y_off;
  2200.                 buf1[offs] = tube_pic[y * 256 + x] + 16;
  2201.             }
  2202.         }
  2203.         MD_Update();
  2204.         WaitRetrace();
  2205.         ShowPic( buf1 );
  2206.         x_off += 3;
  2207.         y_off += 3;
  2208.     }
  2209.     // "if you played"
  2210.     for( count = 0; count < 50; count++ )
  2211.     {
  2212.         // draw the tube:
  2213.         for( row = 0; row < BUF_HEIGHT; row +=2 )
  2214.         {
  2215.             for( col = 0; col < BUF_WIDTH; col++ )
  2216.             {
  2217.                 offs = row * BUF_WIDTH + col;
  2218.                 x = circ_x[offs];
  2219.                 y = circ_y[offs]+(xGetSin(radii2[offs]*2)>>11);
  2220.                 x += x_off;
  2221.                 y += y_off;
  2222.                 buf1[offs] = tube_pic[y * 256 + x];
  2223.             }
  2224.         }
  2225.         // draw the tube:
  2226.         for( row = 1; row < BUF_HEIGHT; row += 2 )
  2227.         {
  2228.             for( col = 0; col < BUF_WIDTH; col++ )
  2229.             {
  2230.                 offs = row * BUF_WIDTH + col;
  2231.                 x = circ_x[offs];
  2232.                 y = circ_y[offs]+(xGetCos(radii2[offs]*2)>>11);
  2233.                 x -= x_off;
  2234.                 y -= y_off;
  2235.                 buf1[offs] = tube_pic[y * 256 + x] + 16;
  2236.             }
  2237.         }
  2238.         DrawText( "if you", 30, 20, buf1 );
  2239.         DrawText( "played", 70, 100, buf1 );
  2240.         MD_Update();
  2241.         WaitRetrace();
  2242.         ShowPic( buf1 );
  2243.         x_off += 3;
  2244.         y_off += 3;
  2245.     }
  2246.     // "with fire"
  2247.     for( count = 0; count < 50; count++ )
  2248.     {
  2249.         // draw the tube:
  2250.         for( row = 0; row < BUF_HEIGHT; row +=2 )
  2251.         {
  2252.             for( col = 0; col < BUF_WIDTH; col++ )
  2253.             {
  2254.                 offs = row * BUF_WIDTH + col;
  2255.                 x = circ_x[offs];
  2256.                 y = circ_y[offs]+(xGetSin(radii2[offs]*2)>>11);
  2257.                 x += x_off;
  2258.                 y += y_off;
  2259.                 buf1[offs] = tube_pic[y * 256 + x];
  2260.             }
  2261.         }
  2262.         // draw the tube:
  2263.         for( row = 1; row < BUF_HEIGHT; row += 2 )
  2264.         {
  2265.             for( col = 0; col < BUF_WIDTH; col++ )
  2266.             {
  2267.                 offs = row * BUF_WIDTH + col;
  2268.                 x = circ_x[offs];
  2269.                 y = circ_y[offs]+(xGetCos(radii2[offs]*2)>>11);
  2270.                 x -= x_off;
  2271.                 y -= y_off;
  2272.                 buf1[offs] = tube_pic[y * 256 + x] + 16;
  2273.             }
  2274.         }
  2275.         DrawText( "with", (BUF_WIDTH - (20*4))/2, 50, buf1 );
  2276.         DrawText( "fire", (BUF_WIDTH - (20*4))/2, 130, buf1 );
  2277.         MD_Update();
  2278.         WaitRetrace();
  2279.         ShowPic( buf1 );
  2280.         x_off += 3;
  2281.         y_off += 3;
  2282.     }
  2283.  
  2284.     /////////////////////////////////////////////////////////////////////////
  2285.     // SHOW MATCH PIC:
  2286.     /////////////////////////////////////////////////////////////////////////
  2287.     WaitRetrace();
  2288.     SetPal( matchpal );
  2289.     ShowPic( matchpic );
  2290.     // wait a half sec or so:
  2291.     for( count = 0; count < 25; count++ )
  2292.     {
  2293.         MD_Update();
  2294.         WaitRetrace();
  2295.         WaitNoRetrace();
  2296.     }
  2297.  
  2298.     WaitRetrace();
  2299.     ClearBuf( screen, SCREEN_WIDTH * SCREEN_HEIGHT );
  2300.     SetPal( waterpal );
  2301.  
  2302.     /////////////////////////////////////////////////////////////////////////
  2303.     // EXPANDING CIRCLES:
  2304.     /////////////////////////////////////////////////////////////////////////
  2305.     // "would it sound like rain"
  2306.     x_off = 0;
  2307.     int freq, freq_iter;
  2308.     freq_iter = DOUBLE_TO_REAL( 0.08 );
  2309.     freq = DOUBLE_TO_REAL( 4.0 );
  2310.     for( count = 0; count < 50; count++ )
  2311.     {
  2312.         // draw the tube:
  2313.         for( row = 0; row < BUF_HEIGHT; row++ )
  2314.         {
  2315.             for( col = 0; col < BUF_WIDTH; col++ )
  2316.             {
  2317.                 offs = row * BUF_WIDTH + col;
  2318.                 x = radii2[offs];
  2319.                 buf1[offs] = xGetSin( Mul( freq, INT_TO_REAL( x ) )>>16 ) >> 8;
  2320.             }
  2321.         }
  2322.         DrawText( "would it", 40, 20, buf1 );
  2323.         DrawText( "sound", 99, 76, buf1 );
  2324.         DrawText( "like rain?", 30, 140, buf1 );
  2325.         MD_Update();
  2326.         WaitRetrace();
  2327.         ShowPic( buf1 );
  2328.         x += x_off;
  2329.         freq -= freq_iter;
  2330.         x_off--;
  2331.     }
  2332.  
  2333.     /////////////////////////////////////////////////////////////////////////
  2334.     // BACK TO MATCH PIC:
  2335.     /////////////////////////////////////////////////////////////////////////
  2336.     WaitRetrace();
  2337.     SetPal( matchpal );
  2338.     ShowPic( matchpic );
  2339.     // wait half a sec or so:
  2340.     for( count = 0; count < 10; count++ )
  2341.     {
  2342.         MD_Update();
  2343.         WaitRetrace();
  2344.         WaitNoRetrace();
  2345.     }
  2346.  
  2347.     /////////////////////////////////////////////////////////////////////////
  2348.     // WASH OUT MATCH PIC:
  2349.     /////////////////////////////////////////////////////////////////////////
  2350.     for( count = 0; count < 75; count++ )
  2351.     {
  2352.         for( int ycount = 1; ycount < BUF_HEIGHT-1; ycount++ )
  2353.         {
  2354.             for( int xcount = 0; xcount < BUF_WIDTH; xcount++ )
  2355.             {
  2356.                   matchpic[ycount * BUF_WIDTH + xcount] =
  2357.                       ( matchpic[ycount * BUF_WIDTH + xcount -1] +
  2358.                       matchpic[ycount * BUF_WIDTH + xcount +1] +
  2359.                       matchpic[(ycount-1) * BUF_WIDTH + xcount] +
  2360.                       matchpic[(ycount+1) * BUF_WIDTH + xcount] ) / 4;
  2361.             }
  2362.         }
  2363.         MD_Update();
  2364.         WaitRetrace();
  2365.         ShowPic( matchpic );
  2366.     }
  2367.  
  2368.     // fade to black
  2369.     GetPalette( pal );
  2370.     while( !FadeOut( pal ) ){ MD_Update(); }
  2371.  
  2372.     WaitRetrace();
  2373.     ClearBuf( screen, SCREEN_WIDTH * SCREEN_HEIGHT );
  2374.  
  2375.     /////////////////////////////////////////////////////////////////////////
  2376.     // BACK TO THE TUNNEL, WHICH ENDS:
  2377.     /////////////////////////////////////////////////////////////////////////
  2378.     // fade in
  2379.     CopyPal( pal, skypal );
  2380.     done = 0;
  2381.     // "if you watched this demo"
  2382.     while( !done )
  2383.     {
  2384.         // draw the tube:
  2385.         for( row = 0; row < BUF_HEIGHT; row++ )
  2386.         {
  2387.             for( col = 0; col < BUF_WIDTH; col++ )
  2388.             {
  2389.                 offs = row * BUF_WIDTH + col;
  2390.                 x = tube_x[offs];
  2391.                 y = tube_y[offs];
  2392.                 x += x_off;
  2393.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  2394.             }
  2395.         }
  2396.         DrawText( "if you", (BUF_WIDTH - (20*6))/2, 21, buf1 );
  2397.         DrawText( "watched", (BUF_WIDTH - (20*7))/2, 71, buf1 );
  2398.         DrawText( "this demo", (BUF_WIDTH - (20*9))/2, 121, buf1 );
  2399.         MD_Update();
  2400.         done = FadeIn( pal );
  2401.         ShowPic( buf1 );
  2402.         x_off += 3;
  2403.     }
  2404.     // tunnel starts to rotate:
  2405.     // "would you"
  2406.     for( count = 0; count < 32; count++ )
  2407.     {
  2408.         // draw the tube:
  2409.         for( row = 0; row < BUF_HEIGHT; row++ )
  2410.         {
  2411.             for( col = 0; col < BUF_WIDTH; col++ )
  2412.             {
  2413.                 offs = row * BUF_WIDTH + col;
  2414.                 x = tube_x[offs];
  2415.                 y = tube_y[offs];
  2416.                 x += x_off;
  2417.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  2418.             }
  2419.         }
  2420.         DrawText( "would you", (BUF_WIDTH - (20*9))/2, (BUF_HEIGHT - 40)/2, buf1 );
  2421.         MD_Update();
  2422.         WaitRetrace();
  2423.         ShowPic( buf1 );
  2424.         x_off += 3;
  2425.         y_off += 3;
  2426.     }
  2427.     // fade out in 'rings':
  2428.     // "ponder"
  2429.     color_offs = 0;
  2430.     do
  2431.     {
  2432.         // draw the tube:
  2433.         for( row = 0; row < BUF_HEIGHT; row++ )
  2434.         {
  2435.             for( col = 0; col < BUF_WIDTH; col++ )
  2436.             {
  2437.                 offs = row * BUF_WIDTH + col;
  2438.                 x = tube_x[offs];
  2439.                 y = tube_y[offs];
  2440.                 x += x_off;
  2441.                 y += y_off;
  2442.                 buf1[offs] = tube_pic[y * 256 + x] + (radii[offs]*16);
  2443.             }
  2444.         }
  2445.         x_off += 3;
  2446.         y_off += 3;
  2447.  
  2448.         FadeMusicOut();
  2449.         DrawText( "ponder?", (BUF_WIDTH - (AVG_CHAR_WIDTH*7))/2,
  2450.             (BUF_HEIGHT - (40))/2, buf1 );
  2451.         MD_Update();
  2452.         WaitRetrace();
  2453.         FadeOutRing( skypal, color_offs, 1 );
  2454.         if( color_offs >= 16*3 ) FadeOutRing( skypal, color_offs - 16*3, 1 );
  2455.         if( color_offs >= 32*3 ) FadeOutRing( skypal, color_offs - 32*3, 1 );
  2456.         if( color_offs >= 48*3 ) FadeOutRing( skypal, color_offs - 48*3, 1 );
  2457.         if( color_offs >= 64*3 ) FadeOutRing( skypal, color_offs - 64*3, 2 );
  2458.         if( color_offs >= 80*3 ) FadeOutRing( skypal, color_offs - 80*3, 2 );
  2459.         if( color_offs >= 96*3 ) FadeOutRing( skypal, color_offs - 96*3, 2 );
  2460.         if( color_offs >= 112*3 ) FadeOutRing( skypal, color_offs - 112*3, 2 );
  2461.         if( color_offs >= 128*3 ) BlackOutRing( skypal, color_offs - 128*3 );
  2462.  
  2463.         color_offs += 16*3;
  2464.         ShowPic( buf1 );
  2465.     }
  2466.     while( color_offs < 767 );
  2467.  
  2468.  
  2469.     /////////////////////////////////////////////////////////////////////////
  2470.     // END:
  2471.     /////////////////////////////////////////////////////////////////////////
  2472.  
  2473.     // and then wait another 2 seconds or so
  2474.     for( count = 0; count < 100; count++ )
  2475.     {
  2476.         FadeMusicOut();
  2477.         MD_Update();
  2478.         WaitRetrace();
  2479.         WaitNoRetrace();
  2480.     }
  2481.  
  2482.     //MIKMOD stuff:///////////////////////////////////
  2483.     MD_PlayStop();          // stop playing
  2484.     ML_Free(mf);            // and free the module
  2485.     MD_Exit();
  2486.     //////////////////////////////////////////////////
  2487.  
  2488.  
  2489.     // free all allocated memory:
  2490.     delete tube_x;
  2491.     delete tube_y;
  2492.     delete circ_x;
  2493.     delete circ_y;
  2494.     delete radii;
  2495.     delete radii2;
  2496.     delete radii3;
  2497.     delete buf1;
  2498.  
  2499.     // return to text mode
  2500.     SetVidMode( 0x03 );
  2501.  
  2502.     // print an exit message:
  2503.     printf( "\nThank you for watching this 'poetro'\n" );
  2504.     printf( "Please read the file \"ponder.nfo\" for information about this demo\n" );
  2505.     printf( "\nGreetings go out to:\n" );
  2506.     printf( "Dark Avenger\n" );
  2507.     printf( "Midnight\n" );
  2508.     printf( "White Shadow\n" );
  2509.     printf( "Anix\n" );
  2510.     printf( "DeathStar\n" );
  2511.     printf( "Hasty\n" );
  2512.     printf( "Phred\n" );
  2513.     printf( "Shaman / Dream Factory\n" );
  2514.     printf( "Switch\n" );
  2515.     printf( "Xphase\n" );
  2516.     printf( "\nSpecial Greetings to:\n" );
  2517.     printf( "Daredevil / Tran : for PMODE/W\n" );
  2518.     printf( "Liket : for the tweaked 50hz mode\n" );
  2519.     printf( "Mikmak : for mikmod\n" );
  2520.     printf( "all members of Project Eos\n" );
  2521.     printf( "all members of Danaan\n" );
  2522.     printf( "and all #coders smart enough to switch to anothernet ;)\n" );
  2523. }
  2524.